Skip to content

Instantly share code, notes, and snippets.

@stp-che
Last active October 2, 2015 19:58
Show Gist options
  • Save stp-che/2310085 to your computer and use it in GitHub Desktop.
Save stp-che/2310085 to your computer and use it in GitHub Desktop.
Simple backup automation
#!/bin/sh
cd ~/app_workspace
d=`date +%Y%m%d`
path=/home/keeper/backup
pg_dump -U postgres -d my_database -n my_schema -f $path"dump"$d -O
zip -jq $path"dump"$d".zip" $path"dump"$d
zip -q $path"files"$d -r clients_files
require 'rubygems'
require 'net/scp'
require 'pony'
@date = Time.now.strftime '%Y%m%d'
@host = '10.0.0.2'
@user = 'keeper'
@pwd = 'password'
@remote = '/home/keeper/backup/'
@local = '/home/stp/backup/'
def send_msg( subj, msg )
Pony.mail :to => '[email protected]', :from => '[email protected]', :subject => subj, :body => msg
end
begin
Net::SCP.start( @host, @user, :password => @pwd ) do |scp|
scp.download! "#{@remote}dump#{@date}.zip", "#{@local}dump#{@date}.zip"
scp.download! "#{@remote}files#{@date}.zip", "#{@local}files#{@date}.zip"
end
send_msg 'daily backup is OK', 'Backup has been downloaded successfully'
rescue Net::SCP::Error => e
send_msg 'daily backup FAILED', "Something WRONG\nBackup files downloading failed."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment