Automating Remote Backups
For users who prefer to use a desktop tool instead of scripts for setting up and performing backups, there is the Grsync tool. This is a GTK+-based tool that provides a nearly complete front end to rsync. It can be used to select a single source and destination and is likely available from Linux distribution repositories.
Although previous versions appear to have had an integrated cron configuration, the current version available with Fedora does not. Also, Grsync does not allow selection of multiple source files or directories nor does it allow setting exclusion lists. Both of these are supported by the rsync command line. Grsync can create a session file that can be called from cron, but it does not include information on how to notify the user of the results of the backup.
Due to the lack of cron integration, missing include and exclude options and no integration of user notification, Grsync is not an ideal backup solution. The scripts described here, along with the addition of ssmtp for simplified SMTP-based notification, are a better solution.
With SSH set up and the choice to script backups instead of using a desktop application out of the way, it is time to consider what files to back up. Four sets of files should be considered: system configuration files, database files, users' home directories and Web files.
System configuration files include files such as the password and group files, hosts, exports and resolver files, MySQL and PHP configurations, SSH server configuration and so forth. Backup of various system configuration files is important even if it's not desirable to reuse them directly during a system re-install. The password and group files, for example, shouldn't be copied verbatim to /etc/passwd and /etc/group but rather used as reference to re-create user logins matched to their home directories and existing groups. The entire /etc directory can be backed up, although in practice, only a few of these files need to be re-installed or merged after a distribution re-installation.
Some applications built from source, such as ssmtp, which will be used for notification in the backup scripts, may install to /usr/local or /opt. Those directories can be backed up too, or the applications can be rebuilt after a distribution upgrade.
MySQL database files can be backed up verbatim, but it may be easier to dump the databases to a text file and then reload them after an upgrade. This method should allow for the database to handle version changes cleanly.
User home directories typically contain all user data. Generally, all files under /home except the /home/lost+found directory should be backed up. This assumes that all user logins are kept on /home. Check your distribution documentation to verify the location of user home directories.
Home users may not use Web servers internally, but there is no reason they shouldn't be. Wikis, blogs, media archives and the like are easy to set up and offer a family a variety of easy-to-use communication systems within the home. Setting up document root directories (using Apache configuration files) under /home makes backing up these files identical to any other user files.
There are also files and directories to avoid when performing backups. The lost+found directory always should be excluded, as should $HOME/.gvfs, which is created for GNOME users after they log in.
All of the backups can be handled by a single script, but because backup needs change often, I find it easier to keep with UNIX tradition and created a set of four small scripts for managing different backup requirements.
The first script is used to run the other scripts and send e-mail notifications of the reports on the backup process. This script is run by root via cron each night:
#!/bin/bash HOST=`hostname` date=`date` mailfile="/tmp/$$.bulog" # Mail Header echo "To: email@example.com" > $mailfile echo "From: firstname.lastname@example.org" >> $mailfile echo "Subject: $HOST: Report for $date" >> $mailfile echo " " >> $mailfile echo "$HOST backup report:" >> $mailfile echo "-------------------------------" >> $mailfile # Run the backup. $1 >> $mailfile 2>&1 # Send the report. cat $mailfile | \ /usr/local/ssmtp/sbin/ssmtp -t \ -email@example.com -apyourpassword \ -amCRAM-MD5 rm $mailfile
The first argument to the script is the backup script to run. An enhanced version would verify the command-line option before attempting to run it.
This script uses an external program (ssmtp) for sending backup reports. If you have an alternative tool for sending e-mail from the command line, you can replace ssmtp usage with that tool. Alternatively, you can skip using this front end completely and run the backup scripts directly from cron and/or the command line.
6 hours 48 min ago
- Why choose a Flash based product?
7 hours 25 min ago
19 hours 46 min ago
1 day 11 hours ago
- Thanks for clearing that up.
1 day 17 hours ago
- Nice coding on the cake. I
2 days 4 hours ago
- Baker's identity
2 days 9 hours ago
- Uber jealous
2 days 14 hours ago
- Reality is disapointing
3 days 1 hour ago
- Máy sấy quần áo
3 days 3 hours ago