|
|||
|
Basic Backups with rsync You can perform basic complete backups with rsync just like with cfengine. Here is an example shell script that can be executed on a daily basis on each of your systems: #!/bin/bash BACKUP_PATH=backup@backup.mydomain.com:/usr/local/backup DIRS="/etc /var /usr/local /home" weekday='date +%a' shorthost='hostname | sed 's/\..*$//'' rsync -a --delete $DIRS "$BACKUP_PATH/$shorthost/$weekday" The -a switch places rsync into archive mode, which means all permissions and ownership are preserved. In addition, symbolic links, special files, and directories are also preserved. rsync also operates recursively when in archive mode, so there is no reason to specify the -r option. The –delete switch causes any files within the destination directory that are not present in the source directory to be deleted. Since the backup directories are based on the day of the week and are reused from week to week, you need this option to prevent your backups from continuously growing. This also allows you to create a true snapshot of the system. If you don't have enough disk space to keep multiple days worth of backup for each host, you may need to use the script or move the data to tapes. If none of this is possible, you may need to keep only one day's worth of backups using this slightly simpler script: #!/bin/bash BACKUP_PATH=backup@backup.mydomain.com:/usr/local/backup DIRS="/etc /var /usr/local /home" shorthost='hostname | sed 's/\..*$//'' rsync -a $DIRS "$BACKUP_PATH/$shorthost" Note that I removed the –delete switch from the second example. This would not delete any files on the backup server, allowing you to retrieve files that were accidentally deleted more than 24 hours ago. It doesn't help with corrupted files because the corrupted version will be copied to the backup server anyway. You will also need to occasionally wipe out the backup directory (or run the script with the –delete switch) to prevent it from growing continuously. |