{"id":467,"date":"2014-04-20T22:23:31","date_gmt":"2014-04-21T05:23:31","guid":{"rendered":"http:\/\/10.43.101.63:24469\/?page_id=467"},"modified":"2022-10-05T11:29:20","modified_gmt":"2022-10-05T18:29:20","slug":"duplicity-wrapper-script","status":"publish","type":"page","link":"https:\/\/aarontc.com\/projects\/duplicity-wrapper-script\/","title":{"rendered":"Duplicity Wrapper Script"},"content":{"rendered":"

For many years I relied upon rdiff-backup<\/a> 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<\/a>!<\/p>\n

Like rdiff-backup, duplicity is best operated by a wrapper script from a cron job, to keep everything running in a smooth and automatic fashion. To this end, I’ve updated my rdiff-backup Bash wrapper script<\/a> to use duplicity instead. The script 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>\n#<\/span>\nVERSION=<\/span>1.1.0\n# 2015\/01\/05<\/span>\n#<\/span>\n# Please do not put spaces in the name of this script,<\/span>\n# the lock file is based on $0 and spaces break things.<\/span>\n#<\/span>\n# You will want something like this in ~\/.ssh\/config, where the virtual host<\/span>\n# name corresponds to the NAME variable below:<\/span>\n#<\/span>\n# Host my-backup<\/span>\n#\tHostname backupserver.my.lan<\/span>\n#\tUser backup<\/span>\n#\tIdentityfile \/root\/.ssh\/id_rsa_my-backup<\/span>\n#\tCompression yes<\/span>\n#\tProtocol 2<\/span>\n#<\/span>\n#<\/span>\n#<\/span>\n# Changelog:<\/span>\n#<\/span>\n# 2015\/01\/05 - Aaron Ten Clay<\/span>\n#              Add '\/root\/.cache\/duplicity' as the explicit cache path<\/span>\n#              Add '\/root\/.cache\/duplicity' to default exclusionlist<\/span>\n#              Used 'NAME' variable in backup path<\/span>\n#              Added default 'full if older than 4 months' argument<\/span>\n#<\/span>\n# 2014\/05\/13 - Aaron Ten Clay<\/span>\n#              Add '\/mnt' to default exclusionlist, again. Should not have been removed.<\/span>\n#<\/span>\n# 2014\/03\/27 - Aaron Ten Clay<\/span>\n#              Changed to duplicity since rdiff-backup is now unmaintained<\/span>\n#<\/span>\n# 2011\/09\/05 - Aaron Ten Clay<\/span>\n#              Corrected output redirection and added filtering for harmless error messages<\/span>\n#<\/span>\n# 2011\/04\/10 - Aaron Ten Clay<\/span>\n#              Updated order of include\/exclude arguments to capture kernel config<\/span>\n#              Added output filtering via Grep to ignore SpecialFileError messages<\/span>\n#<\/span>\n# 2009\/07\/20 - Aaron Ten Clay<\/span>\n#              Added rudimentary version checking<\/span>\n#<\/span>\n# 2009\/02\/21 - Aaron Ten Clay<\/span>\n#              Fixed spelling error<\/span>\n#<\/span>\n# 2009\/01\/20 - Aaron Ten Clay<\/span>\n#              Repaired grammar in error messages<\/span>\n#<\/span>\n# 2009\/01\/17 - Aaron Ten Clay<\/span>\n#              Repaired remote version error message<\/span>\n#<\/span>\n\n\n# Quick customization parameters<\/span>\nNAME=<\/span>\"my-backup\"<\/span>\nTARGET=<\/span>\"rsync:\/\/<\/span>${NAME}<\/span>\/root\"<\/span>\nPASSPHRASE=<\/span>\"super-secret-passphrase-here\"<\/span>\n\n# Main script<\/span>\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\/duplicity-wrapper-script\/version-check?version=<\/span>${VERSION}<\/span>\"<\/span>)<\/span>\n\tif<\/b> [[<\/b> \"x<\/span>${latest}<\/span>\"<\/span> ==<\/span> \"x\"<\/span> ]]<\/b>; then<\/b>\n\t\techo<\/span><\/b> \"Notice: Version check failed\"<\/span>\n\telse<\/b>\n\t\tif<\/b> [[<\/b> \"<\/span>${latest}<\/span>\"<\/span> !=<\/span> \"latest\"<\/span> ]]<\/b>; then<\/b>\n\t\t\techo<\/span><\/b> \"Notice: Version check returned: <\/span>${latest}<\/span>\"<\/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>\n\n# Exit if using uninitialized variable<\/span>\nset<\/b> -o<\/span><\/b> nounset\n\ncheck_script_version<\/span><\/b>\n\nlockfile=<\/span>\"\/tmp\/<\/span>$(<\/span>basename<\/span><\/b> $0)<\/span>.pid\"<\/span>\n\nif<\/b> (<\/b> set<\/b> -o<\/span><\/b> noclobber;<\/b> echo<\/span><\/b> \"<\/span>$<\/span>\"<\/span> ><\/span><\/b> \"<\/span>$lockfile<\/span>\"<\/span>)<\/b> 2><\/span><\/b> \/dev\/null<\/span><\/b>; then<\/b>\n\ttrap<\/span><\/b> sigcaught INT TERM EXIT\n\texport<\/span><\/b> PASSPHRASE<\/span>\n\n\tduplicity<\/span><\/b> \\\n\t\t--full-if-older-than 4M \\\n\t\t--archive-dir \/root\/.cache\/duplicity \\\n\t\t--exclude \/root\/.cache\/duplicity \\\n\t\t--exclude \/dev \\\n\t\t--exclude \/media \\\n\t\t--exclude \/mnt \\\n\t\t--exclude \/opt \\\n\t\t--exclude \/proc \\\n\t\t--exclude \/sys \\\n\t\t--exclude \/tmp \\\n\t\t--exclude \/usr\/portage \\\n\t\t--exclude \/usr\/tmp \\\n\t\t--include \/usr\/src\/linux\/.config \\\n\t\t--exclude \/usr\/src \\\n\t\t--exclude \/var\/cache \\\n\t\t--exclude \/var\/log \\\n\t\t--exclude \/var\/tmp \\\n\t\t--asynchronous-upload \\\n\t\t--name \"<\/span>${NAME}<\/span>\"<\/span> \\\n\t\t--no-print-statistics \\\n\t\t--volsize 100 \\\n\t\t$*<\/span> \\\n\t\t\"\/\"<\/span> \\\n\t\t\"<\/span>${TARGET}<\/span>\"<\/span> \\\n\t\t2>&1<\/span><\/b>\n\n\trm<\/span><\/b> -f \"<\/span>$lockfile<\/span>\"<\/span>\n\ttrap<\/span><\/b> - INT TERM EXIT\nelse<\/b>\n\techo<\/span><\/b> \"Error: Failed to acquire lockfile: <\/span>$lockfile<\/span>, held by PID <\/span>$(<\/span>cat<\/span><\/b> $lockfile)<\/span>\"<\/span> >&2<\/span><\/b>\nfi<\/b>\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

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 a wrapper script from a […]<\/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-7x","jetpack-related-posts":[{"id":152,"url":"https:\/\/aarontc.com\/articles\/rdiff-backup-a-wrapper-script\/","url_meta":{"origin":467,"position":0},"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":132,"url":"https:\/\/aarontc.com\/projects\/rdiff-backup-wrapper-script\/","url_meta":{"origin":467,"position":1},"title":"Rdiff-Backup Wrapper Script","author":"Aaron","date":"May 16, 2010","format":false,"excerpt":"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\u2026","rel":"","context":"With 1 comment","block_context":{"text":"With 1 comment","link":"https:\/\/aarontc.com\/projects\/rdiff-backup-wrapper-script\/#comments"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":30,"url":"https:\/\/aarontc.com\/projects\/","url_meta":{"origin":467,"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":[]}],"_links":{"self":[{"href":"https:\/\/aarontc.com\/wp-json\/wp\/v2\/pages\/467"}],"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=467"}],"version-history":[{"count":9,"href":"https:\/\/aarontc.com\/wp-json\/wp\/v2\/pages\/467\/revisions"}],"predecessor-version":[{"id":25434,"href":"https:\/\/aarontc.com\/wp-json\/wp\/v2\/pages\/467\/revisions\/25434"}],"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=467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}