Class: AnjeaBackup::Backup
- Inherits:
-
Object
- Object
- AnjeaBackup::Backup
- Defined in:
- lib/anjea_backup/anjea_backup.rb
Instance Method Summary collapse
- #backup ⇒ Object
- #cleanup ⇒ Object
-
#initialize ⇒ Backup
constructor
A new instance of Backup.
- #to_vault ⇒ Object
Constructor Details
#initialize ⇒ Backup
Returns a new instance of Backup.
26 27 28 29 30 31 32 33 34 |
# File 'lib/anjea_backup/anjea_backup.rb', line 26 def initialize read_system_conf if !lock! log_err "Aborting, anjea already running. Delete #{@lock_file} if not." exit 2 end read_backups_conf setup_dirs end |
Instance Method Details
#backup ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/anjea_backup/anjea_backup.rb', line 36 def backup yyyymmdd = DateTime.now.strftime("%Y-%m-%d-%H") # TODO work in a tmp work dir @backup_items.each do |item| last_backup = File.join(@last, item.name) today_backup = create_now_backup_path(yyyymmdd, item) work_dir = File.join(@partial, item.name, yyyymmdd) FileUtils.mkdir_p work_dir source = item.ssh_url ? "-e \"ssh -i #{item.ssh_key}\" #{item.ssh_url}" : item.src_dir rsync_cmd = "rsync -avz --delete --relative --stats --log-file #{log_file_for(yyyymmdd, item)} --link-dest #{last_backup} #{source} #{today_backup}" log item, "rsync start" if system(rsync_cmd) log item, "rsync finished" # 'finish', move partial to backup-dest link_last_backup today_backup, last_backup log item, "linked" else # TODO Move this one into quarantaine/incomplete! log_err item, "rsync failed?" end end self end |
#cleanup ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/anjea_backup/anjea_backup.rb', line 65 def cleanup now = DateTime.now @backup_items.each do |item| puts "[#{item.name}] backups:" puts "-- #{item.description} --" ages = Dir.glob("#{@destination}/[^c]*/#{item.name}").map do |dir| date_dir = Pathname.new(dir).parent.basename.to_s dtdiff = 0 begin stamp = DateTime.strptime(date_dir, "%Y-%m-%d-%H") dtdiff = now - stamp rescue STDERR.puts "Do not understand timestamp in #{dir}" end [dtdiff, dir] end ages.sort.each do |age,dir| puts "(#{(age*24).to_i}) #{dir}" end puts end end |
#to_vault ⇒ Object
88 89 |
# File 'lib/anjea_backup/anjea_backup.rb', line 88 def to_vault end |