Skip to content

Instantly share code, notes, and snippets.

@rsanheim
Created July 28, 2008 06:47
Show Gist options
  • Save rsanheim/2852 to your computer and use it in GitHub Desktop.
Save rsanheim/2852 to your computer and use it in GitHub Desktop.
stupid simple backup script
#!/usr/bin/env ruby
# Stupid simple rsync backup script
# The first arg is an optional bandwidth limit, and the second is an optional --v (verbose) flag
def run_cmd_with_live_stdout(cmd)
$stdout.sync = true
STDOUT.sync = true
IO.popen(cmd) do |is|
until is.eof?
char = is.getc
putc char
end
end
end
bw_limit = ARGV[0] || 80
verbose = ARGV[1] && (ARGV[1] == "--v")
destination = "host.com:path"
dirs_to_backup = %w[
/Users/foo/Library/
~/Pictures/
~/Music/]
puts "Beginning backup - maximum bandwith of #{bw_limit}"
puts "On backup list: \n#{dirs_to_backup.join("\n")}"
dirs_to_backup.each do |dir|
puts "Backing up #{dir}..."
cmd = "/usr/bin/rsync #{"--verbose" if verbose} --progress --bwlimit=#{bw_limit} --stats -avz --exclude=.DS_Store #{dir} #{destination}"
run_cmd_with_live_stdout(cmd)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment