Last active
August 29, 2015 14:21
-
-
Save jmlrt/bba42cad9eced1145f51 to your computer and use it in GitHub Desktop.
Duplicity Rakefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rakefile | |
# Use env.rb for environment variables | |
require "./env" | |
# Duplicity command | |
$cmd = "/usr/local/bin/duplicity --ssh-options=\"-oIdentityFile=#{$keyfile}\"" | |
# Print message | |
def msg(task, dir) | |
msg = "*** #{task.upcase} - #{dir.upcase} ***" | |
puts "-" * msg.length | |
puts msg | |
puts "-" * msg.length | |
end | |
# List directories on backup server | |
def listdir | |
return %x[ssh -i #{$keyfile} #{$rmtsrv} ls #{$backuproot}] | |
end | |
# Check if directory exists on backup server | |
def exists(dir) | |
sh "ssh -i #{$keyfile} #{$rmtsrv} test -d #{$backuproot}/#{dir}", verbose: false | |
end | |
# Match source directory to backup directory if needed | |
def getsrc(dir) | |
src = case dir | |
when "documents" then dir.capitalize | |
when "movies" then dir.capitalize | |
when "photos" then "Pictures/JM_Photos.photoslibrary/Masters" | |
else dir | |
end | |
return src | |
end | |
task :default => :listdir | |
desc "list directories to backup" | |
task :listdir do | |
puts listdir | |
end | |
desc "backup directory in argument" | |
task :backup, :dir do |t, args| | |
msg(t.name, args.dir) | |
exists(args.dir) | |
src = getsrc(args.dir) | |
sh "ulimit -n 1024 && export PASSPHRASE=#{$passphrase} && \ | |
#{$cmd} --full-if-older-than #{$delay} --volsize #{$volsize} \ | |
#{$homedir}/#{src} scp://#{$rmtsrv}/#{$backuproot}/#{args.dir}" \ | |
, verbose: false | |
end | |
desc "backup all directories" | |
task :backupall do | |
dirs = listdir.split | |
dirs.each do |d| | |
Rake::Task["backup"].invoke("#{d}") | |
Rake::Task["backup"].reenable | |
end | |
end | |
desc "purge old backups for directory in argument" | |
task :purge, :dir do |t, args| | |
msg(t.name, args.dir) | |
exists(args.dir) | |
sh "export PASSPHRASE=#{$passphrase} && #{$cmd} \ | |
remove-older-than #{$delay} \ | |
scp://#{$rmtsrv}/#{$backuproot}/#{args.dir}", verbose: false | |
end | |
desc "list files backuped for directory in argument" | |
task :list, :dir do |t, args| | |
msg(t.name, args.dir) | |
exists(args.dir) | |
sh "export PASSPHRASE=#{$passphrase} && #{$cmd} \ | |
list-current-files scp://#{$rmtsrv}/#{$backuproot}/#{args.dir}" \ | |
, verbose: false | |
end | |
desc "verify backup for directory in argument" | |
task :verify, :dir do |t, args| | |
msg(t.name, args.dir) | |
exists(args.dir) | |
src = getsrc(args.dir) | |
sh "export PASSPHRASE=#{$passphrase} && #{$cmd} verify \ | |
--compare-data scp://#{$rmtsrv}/#{$backuproot}/#{args.dir} \ | |
#{$homedir}/#{src}", verbose: false | |
end | |
desc "get backup status for directory in argument" | |
task :status, :dir do |t, args| | |
msg(t.name, args.dir) | |
exists(args.dir) | |
sh "export PASSPHRASE=#{$passphrase} && #{$cmd} collection-status \ | |
scp://#{$rmtsrv}/#{$backuproot}/#{args.dir}", verbose: false | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# env.rb | |
# environnement variable for Rakefile | |
$homedir = "" | |
$rmtsrv = "" | |
$backuproot = "" | |
$keyfile = "" | |
$passphrase = "" | |
$delay = "" | |
$volsize = "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a Rakefile to manage my backup on remote server via duplicity