{"id":132,"date":"2010-05-16T05:02:26","date_gmt":"2010-05-16T12:02:26","guid":{"rendered":"http:\/\/10.43.101.63:24469\/?page_id=132"},"modified":"2022-10-05T11:30:18","modified_gmt":"2022-10-05T18:30:18","slug":"rdiff-backup-wrapper-script","status":"publish","type":"page","link":"https:\/\/aarontc.com\/projects\/rdiff-backup-wrapper-script\/","title":{"rendered":"Rdiff-Backup Wrapper Script"},"content":{"rendered":"
I use rdiff-backup<\/a> on all my servers and desktop machines, including routers, laptops, etc. to make sure all data and configuration files are safe. To this end, especially for Linux\/unix hosts, I’ve created a Bash script which takes care of process locking and excluding files which shouldn’t go into the archive. In hopes it’ll be useful to someone, you can download it<\/a>, or view it:<\/p>\n#!\/bin\/bash<\/span><\/i>\n#<\/span><\/i>\nVERSION=<\/span>0.11\n# 2011\/09\/05<\/span><\/i>\n#<\/span><\/i>\n# Please do not put spaces in the name of this script,<\/span><\/i>\n# the lock file is based on $0 and spaces break things.<\/span><\/i>\n#<\/span><\/i>\n# You will want something like this in ~\/.ssh\/config, where the virtual host<\/span><\/i>\n# name corresponds to the REMOTEHOST variable below:<\/span><\/i>\n#<\/span><\/i>\n# Host my-backup<\/span><\/i>\n# \tHostname backupserver.my.lan<\/span><\/i>\n# \tUser backup<\/span><\/i>\n# \tIdentityfile \/root\/.ssh\/id_rsa_my_backup<\/span><\/i>\n# \tCompression yes<\/span><\/i>\n# \tProtocol 2<\/span><\/i>\n#<\/span><\/i>\n#<\/span><\/i>\n#<\/span><\/i>\n# Changelog:<\/span><\/i>\n#<\/span><\/i>\n# 2011\/09\/05 - Aaron Ten Clay<\/span><\/i>\n# Corrected output redirection and added filtering for harmless error messages<\/span><\/i>\n#<\/span><\/i>\n# 2011\/04\/10 - Aaron Ten Clay<\/span><\/i>\n# Updated order of include\/exclude arguments to capture kernel config<\/span><\/i>\n# Added output filtering via Grep to ignore SpecialFileError messages<\/span><\/i>\n#<\/span><\/i>\n# 2009\/07\/20 - Aaron Ten Clay<\/span><\/i>\n# Added rudimentary version checking<\/span><\/i>\n#<\/span><\/i>\n# 2009\/02\/21 - Aaron Ten Clay<\/span><\/i>\n# Fixed spelling error<\/span><\/i>\n#<\/span><\/i>\n# 2009\/01\/20 - Aaron Ten Clay<\/span><\/i>\n# Repaired grammar in error messages<\/span><\/i>\n#<\/span><\/i>\n# 2009\/01\/17 - Aaron Ten Clay<\/span><\/i>\n# Repaired remote version error message<\/span><\/i>\n#<\/span><\/i>\n\n\n# Quick customization parameters<\/span><\/i>\nHOSTNAME=<\/span>\"your.host.name\"<\/span>\nLOCALVERSION=$(<\/span>rdiff-backup --version)<\/span>\nREMOTEPATH=<\/span>\"\/backups\/<\/span>${HOSTNAME}<\/span>\/root\"<\/span>\nREMOTEHOST=<\/span>\"my-backup\"<\/span>\n\n\n# Main script<\/span><\/i>\n\nfunction<\/b> check_script_version<\/span> {<\/b>\n\tlatest=$(<\/span>wget<\/span><\/b> --no-check-certificate -qO- \"http:\/\/10.43.101.63:24469\/projects\/rdiff-backup-wrapper-script\/version_check.php?version=<\/span>${VERSION}<\/span>\"<\/span>)<\/span>\n\tif <\/b>[[ \"x<\/span>${latest}<\/span>\"<\/span> == \"x\"<\/span> ]]; then<\/b>\n\t\techo<\/span><\/b> \"Notice: Version check failed\"<\/span>\n\telse<\/b>\n\t\tif <\/b>[[ \"<\/span>${latest}<\/span>\"<\/span> != \"latest\"<\/span> ]]; then<\/b>\n\t\t\techo<\/span><\/b> -e \"Notice: A newer version (<\/span>${latest}<\/span>) of this script is available at http:\/\/10.43.101.63:24469\/projects\/rdiff-backup-wrapper-script\\n\"<\/span>\n\t\tfi<\/b>\n\tfi<\/b>\n}<\/b>\n\nfunction<\/b> sigcaught ()<\/span> {<\/b>\n\trm<\/span><\/b> -f \"<\/span>$lockfile<\/span>\"<\/span>\n\techo<\/span><\/b> \"Error: caught interrupt\"<\/span> >&2<\/span><\/b>\n\texit<\/span><\/b> 2\n}<\/b>\n\n\n\n# Here begins the actual work<\/span><\/i>\n\n# Exit if using uninitialized variable<\/span><\/i>\nset<\/b> -o nounset\n\ncheck_script_version\n\nremoteversion=$(<\/span>ssh<\/span><\/b> ${REMOTEHOST}<\/span> rdiff-backup --version)<\/span>\n\nif <\/b>[[ \"<\/span>${LOCALVERSION}<\/span>\"<\/span> != \"<\/span>${remoteversion}<\/span>\"<\/span> ]]; then<\/b>\n\techo<\/span><\/b> \"Error: Remote version (<\/span>${remoteversion}<\/span>) differs from local version (<\/span>${LOCALVERSION}<\/span>), aborting\"<\/span> >&2<\/span><\/b>\n\texit<\/span><\/b> 1\nfi<\/b>\n\nlockfile=<\/span>\"\/tmp\/<\/span>$(<\/span>basename<\/span><\/b> $0)<\/span>.pid\"<\/span>\n\nif (<\/b> set<\/b> -o noclobber; echo<\/span><\/b> \"<\/span>$<\/span>\"<\/span> ><\/span><\/b> \"<\/span>$lockfile<\/span>\"<\/span>)<\/b> 2><\/span><\/b> \/dev\/null; then<\/b>\n\ttrap<\/span><\/b> sigcaught INT TERM EXIT\n\n\trdiff-backup \\<\/b>\n\t\t--exclude \/home\/shares \\<\/b>\n\t\t--exclude \/dev \\<\/b>\n\t\t--exclude \/media \\<\/b>\n\t\t--exclude \/mnt \\<\/b>\n\t\t--exclude \/opt \\<\/b>\n\t\t--exclude \/proc \\<\/b>\n\t\t--exclude \/sys \\<\/b>\n\t\t--exclude \/tmp \\<\/b>\n\t\t--exclude \/usr\/portage \\<\/b>\n\t\t--exclude \/usr\/tmp \\<\/b>\n\t\t--include \/usr\/src\/linux\/.config \\<\/b>\n\t\t--exclude \/usr\/src \\<\/b>\n\t\t--exclude \/var\/cache \\<\/b>\n\t\t--exclude \/var\/log \\<\/b>\n\t\t--exclude \/var\/tmp \\<\/b>\n\t\t--exclude \/var\/lib\/vmware \\<\/b>\n\t\t--exclude \/var\/lib\/gentoo \\<\/b>\n\t\t$*<\/span> \\<\/b>\n\t\t\"\/\"<\/span> \\<\/b>\n\t\t\"<\/span>${REMOTEHOST}<\/span>::<\/span>${REMOTEPATH}<\/span>\"<\/span> \\<\/b>\n\t\t2>&1<\/span><\/b> \\<\/b>\n\t\t|<\/b> grep<\/span><\/b> -v \"^SpecialFileError .* Socket error: AF_UNIX path too long<\/span><\/pre>\n
<\/pre>\n
quot;<\/span> \\<\/b> |<\/b> grep<\/span><\/b> -v \"^UpdateError .* Updated mirror temp file .* does not match source<\/span><\/pre>\n
<\/pre>\n
quot;<\/span> \\<\/b> |<\/b> grep<\/span><\/b> -v \"^ListError .* No such file or directory: .*<\/span><\/pre>\n
<\/pre>\n