|
NAMEtartarus - a flexible script based backup systemSYNOPSIStartarus [--inc] profileDESCRIPTIONTartarus provides a nice wrapper around basic Unix tools such as tar, find and curl to provide a seamless backup solution. Instead of relying on single usage backup scripts or complicated command lines, tartarus reads its configuration from easily manageable configuration files. It can store gathered data in regular files, or upload the backup directly (on the fly) to an FTP server. For more specific usage scenarios, custom methods can also be defined within the config file.OPTIONS AND ARGUMENTS
One additional argument is required to specify the profile file to load the backup configuration from. CONFIGURATIONTartarus reads it options from a configuration file specified at the command line. This file is in fact a shell script and has the duty of setting several variables that control the behaviour of the backup script. Each configuration file is called a profile.Parameters can be set by a simple variable assignment or by using more complex methods for advanced use. Whenever a boolean value is expected, the strings "yes" and "no" as well as 1 and 0 are accepted.
EXAMPLEBasic configurationSuppose you want to backup your home directories on a regular basis; the compressed archive will be stored on a FTP server. This can be achieved easily with just a few lines of tartarus configuration. Let's call the profile definition /etc/tartarus/homedirs.conf:# That's the profile name NAME="homedirs" DIRECTORY="/home" # We store it using FTP, on the fly STORAGE_METHOD="FTP" STORAGE_FTP_SERVER="ftpbackup.hostingcompany.com" STORAGE_FTP_USER="johndoe" STORAGE_FTP_PASSWORD="verysecret" COMPRESSION_METHOD="bzip2" By calling "tartarus /etc/tartarus/homedirs.conf" the script will gather all files below /home, compress them using bzip2 and store it on the FTP server ftpbackup.hostingcompany.com. LVM snapshotsBacking up a partition that is in use can lead to inconsistent backups. To avoid this, Tartarus supports the use of LVM snapshots to "freeze" the block device and operate on that static copy. The real volume can still be used while changes done to the file system structure are not reflected on the "frozen" block device.To use this feature, the file system you wish to back up has to reside on an LVM volume and the volume group has to have some free space to store the differences between snapshot and real volume that accumulate during the backup run. You also have to make sure that the directory /snap does exist, since tartarus mounts the created snapshot volume below that directory. A few additional lines instruct Tartarus to use the snapshot functionality: # Users keep on working CREATE_LVM_SNAPSHOT="yes" LVM_VOLUME_NAME="/dev/volumegroup0/home" LVM_MOUNT_DIR="/home" # Allocate enough space for any changes during the backup run LVM_SNAPSHOT_SIZE="1000m" Incremental backupsStoring a full backup takes a lot of disk space; Often just storing the files that changed since the last backup is more desirable - this is called a incremental backup.Tartarus can create a flag file on your system that is used as a reference point when doing the next incremental backup. To do this, just add the following line to your config: INCREMENTAL_TIMESTAMP_FILE="/var/spool/tartarus/homedirs" Everytime a full backup run succeeds, this file is "touched" by Tartarus. To create an incremental backup based on that file, just add these lines to a profile: INCREMENTAL_BACKUP="yes" INCREMENTAL_TIMESTAMP_FILE="/var/spool/tartarus/homedirs" Instead of copying the profile file and adding the lines, you can also just reuse the existing configuration profile and start Tartarus with the option "-i": 'tartarus -i /etc/tartarus/homedirs.conf' will create an incremental backups based on the latest flag file deposited by the last full run. As already said, incremental backups are (normally) based on the last full backup; usually, this is called a "differential" backup: [F1]->[D1] [F2]->[D4] \----->[D2] \------>[D5] `--------->[D3] `---------->[D6] While this backup strategy simplifies recovery (since only the most recent full and the most recent differential archive has to be extracted, e.g. F2 and D6), it can waste backup space in some cases. If a large file is added to the system after the full backup has been created, this file will appear in every partial backup afterwards. Another strategy is a "real" incremental backup, which is called a "stacked incremental backup" in Tartarus terminology. Instead of basing the partial backup on the last full run, it is based on the last successfull run - be it complete or partial as well. [F1]->[I1]->[I2]->[I3] [F2]->[I4]->[I5]->[I6] This behaviour will save space, since new (and unchanged) files will only appear in one archive. However, restoring a filesystem will require all archives to be extracted (F2 _and_ I4 _and_ I5 _and_ _I5_) Setting INCREMENTAL_STACKING to "yes" will enable this behaviour and makes Tartarus update the timestamp file after every backup run, not only after full backups. EncryptionTartarus supports symmetric encryption through gpg (GNU Privacy Guard). To utilize it, write your passphrase into a file, for example /etc/tartarus/backups.sec, and place it at a safe location: You might need it one day to restore your precious backup data. Now tell Tartarus where to find the secret passphrase by adding the following lines to your profile:ENCRYPT_SYMMETRICALLY="yes" ENCRYPT_PASSPHRASE_FILE="/etc/tartarus/backups.sec" Also make sure that the passphrase file is only readable by root; otherwise anyone with access to that file can decrypt your backups. Asymmetric encryption is also possible. Just specify a key id to encrypt the backup archive using that public key: ENCRYPT_ASYMMETRICALLY="yes" ENCRYPT_KEY_ID="ABC12345" The resulting backup profile can only be decrypted using the matching private key. Symmetric and asymmetric encryption can also be combined: Then one credential, either the private key or the passphrase, is sufficient to decrypt the backup archive. Restoring a backupEven more important than creating a backup is restoring it. Since Tartarus is largely based on standard unix tools, you won't have to install special software - even a basic rescue system will suffice to retrieve your lost data.Given that the backup is stored on an FTP server, compressed an encrypted, we need the following tools to restore it:
This enumeration is also the order in which to apply these programs; First download the tar archive to your system, then use "gpg --decrypt" to, well, decrypt it. After that you can expand the file by using "gzip -d" (or the equivalent of bzip2) and retrieve the "naked" tar archive, which can then be manipulated by the usual tar commands. If you do not have enough disk space to store the entire backup, you can also restore it on the fly; just use the "pipe" feature of any unix shell: $ curl ftp://USER:PASS@YOURSERVER/home-20080411-1349.tar.bz2.gpg \ | gpg --decrypt \ | bzip2 -d \ | tar tpv The tar command "tpv" prints the archives content while using numeric UID/GID values for files (so it won't change file ownership while in the rescue system). If you really want to extract the archive, replace "t" with an "x" (eXtract). If you are using the afio file format, compression does not take part on the entire stream, but is handled by afio itself on a per file basis. The command line for listing such a backup might look like this: $ curl ftp://USER:PASS@YOURSERVER/home-20080411-1349.tar.bz2.gpg \ | gpg --decrypt \ | afio -Z -P bzip2 -t - To restore incremental backups, just restore the last full backup as well as the most recent incremental one. Defining a custom storage methodTartarus supports the creation of custom storage methods. No changes to the program are necessary to achieve this: Simply set the storage method in the configuration file to "CUSTOM":STORAGE_METHOD="CUSTOM" Then define a shell function with the name "TARTARUS_CUSTOM_STORAGE_METHOD". The method should read the backup data from STDIN, while the proposed archive filename is stored in the shell variable "$FILENAME". The following example uses the secure shell to transmit the archive to a remote location: TARTARUS_CUSTOM_STORAGE_METHOD() { local USER="stefan" local HOST="zirkel.wertarbyte.de" debug "Sending backup to $USER@$HOST:~/$FILENAME through SSH..." ssh $USER@$HOST "cat > ~/$FILENAME" } Any exit code except 0 is considered an error and will abort the backup process. If the archive is to be split into multiple chunks, the storage method might be called more than once. Tartarus processing hooksFor special configuration purposes, the Tartarus scripts offers special hooks where user supplied code can be placed and executed during the backup procedure.The following hooks are called during the run of the program:
Each segment of the backup procedure - gathering , bundling, compression, encryption and storage - itself is also embraced by a pair of hooks. Those functions however are integrated into the pipeline that transports your backup data, so writing to STDOUT or reading from STDIN in a hook might destroy your data. Only do so if you know exactly what you are doing.
To use a hook, define a shell function of the name in your config file. As an example, this hook function transfers all debug messages to your syslog system: TARTARUS_DEBUG_HOOK() { echo $DEBUGMSG | logger } Hooks can also increase the reliability of the snapshot functionality. LVM snapshots can lead to slightly inconsistent file systems, since they do not freeze the file system, but the underlying block device. This is why Tartarus calls 'sync' right before creating the snapshot volume. Most filesystems can cope with that issue. But if you want to make sure that the snapshot file system is valid, hooks can be used to run a file system check on the snapshot volume before mounting it: TARTARUS_PRE_FREEZE_HOOK() { # make sure everything is synced to disk # before snapshotting sync } TARTARUS_POST_FREEZE_HOOK() { # we can access the internal variables # of the tartarus process, but take care! # # $SNAPDEV should contain the volume we are # about to mount, try auto-repair /sbin/fsck -y "$SNAPDEV" } AUTHORStefan Tomanek <stefan.tomanek+tartarus@wertarbyte.de> http://wertarbyte.de/tartarus.shtml
Visit the GSP FreeBSD Man Page Interface. |