Last active
October 2, 2015 19:58
Revisions
-
stp-che revised this gist
Apr 10, 2014 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,5 @@ #!/bin/sh 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 -
stp-che revised this gist
Apr 10, 2014 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ C:\cygwin\bin\sh.exe -l -c 'cd /path/to/loding/script/folder && ruby load_backup.rb' -
stp-che revised this gist
Apr 10, 2014 . 1 changed file with 41 additions and 21 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,29 +1,49 @@ require 'rubygems' require 'fileutils' require 'pony' BACKUP_DIR = "/path/to/backup" REPORT_DIR = "#{File.expand_path File.dirname(__FILE__)}/synch_reports/#{Time.now.strftime('%Y-%m-%d')}" REMOTE_SERVER = 'myserver' REMOTE_USER = 'user' REPORT_RECIPIENTS = '*******' FileUtils.mkdir_p REPORT_DIR unless File.directory?(REPORT_DIR) PARTS_TO_SYNCH = { db: {remote: '/path/to/db/dumps', local: "#{BACKUP_DIR}/db"}, file_storage: {remote: '/path/to/file/storage', local: "#{BACKUP_DIR}/file_storage"} } PARTS_TO_SYNCH.each do |id, opts| file_out = "#{REPORT_DIR}/#{id}.log" file_err = "#{REPORT_DIR}/#{id}_err.log" command = "rsync -avzu #{REMOTE_USER}@#{REMOTE_SERVER}:#{opts[:remote]} #{opts[:local]}" puts command Process.wait spawn(command, out: file_out, err: file_err) end errors = false attachments = {}.tap do |h| Dir["#{REPORT_DIR}/*"].select{|f| File.file?(f) && File.size(f) > 0}.each do |f| errors = true if f =~ /_err/ h[File.basename(f)] = File.read f end end Pony.mail({ to: REPORT_RECIPIENTS, from: '*******', subject: "backup report - #{errors ? 'WITH ERRORS' : 'OK'}", body: "backup report - #{errors ? 'WITH ERRORS' : 'OK'}", attachments: attachments, via: :smtp, via_options: { address: '****', port: '25', user_name: '******', password: '******', authentication: :plain, domain: "******" } }) -
stp-che created this gist
Apr 5, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ #!/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 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ 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 => 'my@email.com', :from => 'my@email.com', :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