{"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
quot;<\/span> rm<\/span><\/b> -f \"<\/span>$lockfile<\/span>\"<\/span> trap<\/span><\/b> - INT TERM EXIT else<\/b> echo<\/span><\/b> \"Error: Failed to acquire lockfile: <\/span>$lockfile<\/span>, held by PID <\/span>$(<\/span>cat<\/span><\/b> $lockfile)<\/span>\"<\/span> >&2<\/span><\/b> fi<\/b><\/pre>\n","protected":false},"excerpt":{"rendered":"

I use rdiff-backup 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 […]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":30,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"jetpack_post_was_ever_published":false,"footnotes":""},"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/P6PV8H-28","jetpack-related-posts":[{"id":467,"url":"https:\/\/aarontc.com\/projects\/duplicity-wrapper-script\/","url_meta":{"origin":132,"position":0},"title":"Duplicity Wrapper Script","author":"Aaron","date":"April 20, 2014","format":false,"excerpt":"For many years I relied upon rdiff-backup to securely backup all my servers and desktop machines, including routers, laptops, etc. Sadly, the rdiff-backup project was abandoned, and the search for a replacement began in earnest. Luckily, a similar (and better) replacement exists: Duplicity! Like rdiff-backup, duplicity is best operated by\u2026","rel":"","context":"Similar post","block_context":{"text":"Similar post","link":""},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":152,"url":"https:\/\/aarontc.com\/articles\/rdiff-backup-a-wrapper-script\/","url_meta":{"origin":132,"position":1},"title":"Rdiff-backup: A wrapper script","author":"Aaron","date":"May 18, 2010","format":false,"excerpt":"Sorry, this page has moved! The new location is http:\/\/10.43.101.63:24469\/projects\/rdiff-backup-wrapper-script. You will be redirected momentarily if your browser supports JavaScript.","rel":"","context":"Similar post","block_context":{"text":"Similar post","link":""},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":30,"url":"https:\/\/aarontc.com\/projects\/","url_meta":{"origin":132,"position":2},"title":"Projects","author":"Aaron","date":"May 5, 2010","format":false,"excerpt":"Autonomous: Self-Governing Routing Ever wondered how you can upgrade that Linux box acting as your network router with a flashy web interface and more features than you can shake a stick at? Well wonder no more. Enter Autonomous, the Self-Governing Routing system with support for IP Masquerading, OpenVPN, L2TP VPNs,\u2026","rel":"","context":"Similar post","block_context":{"text":"Similar post","link":""},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":247,"url":"https:\/\/aarontc.com\/projects\/home-automation-manager\/","url_meta":{"origin":132,"position":3},"title":"Home Automation Manager","author":"Aaron","date":"December 25, 2010","format":false,"excerpt":"Home Automation Manager is designed to easily manage all aspects of home automation, from home theatre to lighting to security. The project is written in Qt4 (console only, for now), and uses XML files to specify virtual interfaces to physical devices. Still working on how to map these virtual devices\u2026","rel":"","context":"With 2 comments","block_context":{"text":"With 2 comments","link":"https:\/\/aarontc.com\/projects\/home-automation-manager\/#comments"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/aarontc.com\/wp-json\/wp\/v2\/pages\/132"}],"collection":[{"href":"https:\/\/aarontc.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/aarontc.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/aarontc.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/aarontc.com\/wp-json\/wp\/v2\/comments?post=132"}],"version-history":[{"count":15,"href":"https:\/\/aarontc.com\/wp-json\/wp\/v2\/pages\/132\/revisions"}],"predecessor-version":[{"id":25435,"href":"https:\/\/aarontc.com\/wp-json\/wp\/v2\/pages\/132\/revisions\/25435"}],"up":[{"embeddable":true,"href":"https:\/\/aarontc.com\/wp-json\/wp\/v2\/pages\/30"}],"wp:attachment":[{"href":"https:\/\/aarontc.com\/wp-json\/wp\/v2\/media?parent=132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}