-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
90 lines (74 loc) · 2.33 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
require 'fileutils'
$:.unshift(File.dirname(__FILE__) + '/lib')
RAILS_ROOT = File.dirname(__FILE__)
RAILS_ENV = 'production'
require 'backup_fu'
$backup_fu_path = File.join(File.dirname(__FILE__))
desc "Dumps the database and backs it up remotely to Amazon S3. (task added by: backup_fu)"
task :backup do
b = BackupFu.new
b.backup
end
namespace :backup_fu do
desc "Copies over the example backup_fu.yml file to config/"
task :setup do
target = File.join($backup_fu_path, 'config', 'backup_fu.yml.example')
destination = File.join(RAILS_ROOT, 'config', 'backup_fu.yml')
if File.exist?(destination)
puts "\nTarget file: #{destination}\n ... already exists. Aborting.\n\n"
else
FileUtils.cp(target, destination)
puts "\nExample backup_fu.yml copied to config/. Please edit this file before proceeding.\n\nSee 'rake -T backup_fu' for more commands.\n\n"
end
end
desc "Dumps the database locally. Does *not* upload to S3."
task :dump do
b = BackupFu.new
b.dump
end
desc "Same as 'rake backup'. Dumps the database and backs it up remotely to Amazon S3."
task :backup do
b = BackupFu.new
b.backup
end
desc "Backs up both the DB and static files."
task :all do
b = BackupFu.new
b.backup
b.backup_static
end
desc "Clean up old backups. By default 5 backups are kept (you can change this with with keep_backups key in config/backup_fu.yml)."
task :cleanup do
b = BackupFu.new
b.cleanup
end
desc "List backups in S3"
task :s3_backups do
b = BackupFu.new
backups = b.list_backups
pp backups
end
desc "Pull a backup file from S3 and overwrite the database with it"
task :restore do
b = BackupFu.new
backup_file = ENV['BACKUP_FILE']
if backup_file.blank?
puts "You need to specify a backup file to restore. Usage:"
puts "BACKUP_FILE=myapp_1999-12-31_12345679_db.tar.gz rake backup_fu:restore"
else
b.restore_backup(backup_file)
end
end
namespace :static do
desc "Zips or Tars and gzips static application files locally. Does *not* upload to S3."
task :dump do
b = BackupFu.new
b.dump_static
end
desc "Backups up static files to Amazon S3. For configuration see the backup_fu README."
task :backup do
b = BackupFu.new
b.backup_static
end
end
end