backup revision 366ce8d807067a97613cb23d49105d8a093c5015
require 'fileutils'
require 'pathname'
# Amount of backups that have to be there at least
BACKUPS_COUNT = 3
# Backups are valid for 7 days
DATA_DIRS = %w(data/repositories data/git_daemon)
verbose: false, dry_run: true, sql_dump_as_postgres_user: false)
end
# We needed to create the directory for the script to continue later on.
puts "created backup in #{backup_instance_dir}"
end
puts "restored backup from #{backup_instance_dir}"
end
if !Dir.exists?(backup_root)
puts "Nothing to prune: There is no backup directory."
return
end
puts "removing old backup: #{dir}"
end
end
end
end
# Create directory even in dry run to let the script continue.
end
exec "pg_dump -U postgres -Fc #{db_name} > #{SQL_DUMP_FILE}"
else
exec "pg_dump -Fc #{db_name} > #{SQL_DUMP_FILE}"
end
end
end
end
end
puts "Error: Backup '#{backup_name}' does not exist in #{backup_root}."
exit
end
end
exec "pg_restore -c -U postgres -d #{db_name} #{SQL_DUMP_FILE}"
else
exec "pg_restore -c -d #{db_name} #{SQL_DUMP_FILE}"
end
end
end
end
end
end
end
def exec(command)
end
end
end
end
end
end
end
# We assume, this script runs in "RAILS_ROOT/script/".
'ontohub_development'
else
'ontohub'
end
else
end
case ARGV.first
when 'create'
when 'restore'
if ARGV.length == 1
puts 'To restore a backup, you need to specify one with the arguments'
puts '"restore backup_name"'
exit
end
backup_name = ARGV[1]
when 'prune'
else
puts 'unknown or missing parameter'
puts 'use parameter "create" or "restore <backup_name>" or "prune"'
exit
end