Linux Training

Linux training for private, public & voluntary sector.

0793 572 8612

City LinUX sample scripts - archive


archive - selectively archives and deletes old files on a remote host


archive [[ -b ] | [[ -f ] | [ -r [ -D ]]] [ -c <config> ] [ -d ] [ -l ] [ -v ] [ -z ] <host_name> | -V


archive is a Bourne shell script which should work equally well on all versions of UNIX and Linux.


archive creates a full backup of local or remote systems using tar or lftp's mirror command. Only local file systems will be included in the archives and the script will attempt to avoid including any cdroms, dvds or loop back file systems.


-b    back up the databases only. (See -f    option below.

-c <config_file>
The default configuration file is /usr/local/etc/ . An alternative configuration file may be set with the -c    option on the command line.

-d sets the script to debug mode (ie. runs with the shell option -x)

-f    backup up the file system only. It is an error to use the -f    option together with either the =b or the -r    option.

-l    turns on logging using the syslog facility. This is particularly useful where statistics are being compiled for presentation to the client, see report.

-r    perform rsync only. It is an error to combine the -r    option with either the -b    or the -b    options.

-D    set the --delete option for rsync .

-v Sets the script to verbose mode. Each significant action will be reported on standard out.

-z    Use gzip to compress the tar file and append .gz to the archive filename. The -z    option is meaningless when a remote system is being archived as the tar file is always compressed prior to transmission across the network.

-V    prints version details to standard out and exits.


5 0 * * * su fulford -c "/usr/local/etc/archive -l albert"

The above is an extract from a root crontab file and illustrates the typical use of the script in practice. All the local file systems on the host "albert" will be backed up to device (or file) nominated in the default configuration file /usr/local/etc/ . Initiation and completion of the script will be logged using the syslog facility.

Note that the script is executed with an ordinary user id. This is to facilitate remote access where root logins are denied. Sudo is used within the script where root access is required.

NB. The hostname albert is being resolved locally and does not require a fully qualified domain.


The script is quite crude and has little or no error checking.



clean, ftchbkup, plbkup.


Clifford W Fulford, City Linux. Contact or +44 (0)793 572 8612.

The layout and associated style sheets for this page are taken from the World Wide Web Consortium and used here under the W3C software licence.