backup 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -3,6 +3,8 @@
3
3
  == What is "Backup"?
4
4
 
5
5
  "Backup" is a RubyGem written for Rails to (easily) handle backing up your database files and assets to either Amazon S3, or any other server using SSH.
6
+ You barely have to get your hands dirty! Backup provides you with 2 (easily) configurable .yml files. These two files are the only ones you will need to use to configure
7
+ all your backups.
6
8
 
7
9
 
8
10
  === Backup makes use of two storage methods:
@@ -11,11 +13,11 @@
11
13
  - Any Remote Server You Can Access Through "SSH"
12
14
 
13
15
 
14
- === Currently it supports:
16
+ === Currently it supports these adapters:
15
17
 
16
18
  - SQLite3
17
19
  - MySQL
18
- - Folder (and Sub Folders) of Assets (Think of: Documents, Images, Etc.)
20
+ - Assets/Folders (and Sub Folders) of Assets (Think of: Documents, Images, Etc.)
19
21
 
20
22
 
21
23
  === Your database type not on the list?
@@ -25,7 +27,21 @@
25
27
  I built in a simple class (called: Custom) that will allow you to manually create a SQL dump using a shell command.
26
28
  This looks basically the same as the other options, except that you will have to write (probably) only a "single
27
29
  line'd shell command" to generate a sql dump file. Once you generate the file, Backup will take care of the rest
28
- of the (optional)archiving, compressing and pushing to S3 or any remote server that supports SSH.
30
+ of the (optional)archiving, compressing, encrypting and pushing to Amazon S3 or any remote server that supports SSH.
31
+
32
+ === Encryption
33
+
34
+ Backup also provides encryption. Adding a single line to one of the configuration files will enable encryption for your backups!
35
+
36
+ == Why?
37
+
38
+ - I wanted a simple Backup Gem for Rails
39
+ - I wanted minimum and easy configuration
40
+ - I wanted it to take less than 2 minutes to set up
41
+ - I wanted it to support (AT LEAST) both SQLite3 as well as MySQL
42
+ - I wanted it to support an additional (custom) adapter incase the database type isn't SQLite3 or MySQL
43
+ - I wanted it to support some encryption
44
+ - I wanted to be able to store my files on my private backup server and on Amazon S3
29
45
 
30
46
  ==== Setting up Backup takes me about 1-2 minutes and it's really easy!
31
47
 
@@ -64,6 +80,28 @@ http://wiki.github.com/meskyanichi/backup/resources
64
80
  If anyone wishes to see support for PostgreSQL or any other database format, please send me a message!
65
81
 
66
82
 
83
+ === Suggestions?
84
+
85
+ Send me a message! Fork the project! Help out! :)
86
+
87
+
88
+ === Found a Bug?
89
+
90
+ Report it!
91
+ http://github.com/meskyanichi/backup/issues
92
+
93
+
94
+ === Upcoming Feature(s)
95
+
96
+ The ability to set the amount of backups you wish to keep stored.
97
+ This will be configurable inside the .yml files.
98
+ It'd look something like this:
99
+
100
+ keep_backups: 50
101
+
102
+ When this is set, and the 51th backup gets stored, it will remove the oldest one from S3 or what ever other
103
+ server you've set up to back up to.
104
+
67
105
  === Copyright
68
106
 
69
107
  Copyright (c) 2009 Michael van Rooijen | Final Creation. See LICENSE for details.
data/Rakefile CHANGED
@@ -6,9 +6,16 @@ begin
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "backup"
8
8
  gem.summary = %Q{Backup is a gem/plugin that enables you to very easily create backups and transfer these to Amazon S3 or another server with SSH.}
9
- gem.description = %Q{Backup is a gem/plugin that enables you to very easily create backups and transfer these to Amazon S3 or another server with SSH.
10
- It currently supports MySQL, SQLite3 and basic Assets (documents, images, etc). The files will get tar'd / gzip'd and get a timestamp.
11
- After creation, these files can be transferred to either Amazon S3 or any remote server through SSH.}
9
+ gem.description = %Q{
10
+ “Backup” is a RubyGem, written for Ruby on Rails. It's main purpose is to Backup any
11
+ files to Amazon S3 or any remotely accessible server through SSH (SCP). It supports database
12
+ and regular file backups. On top of that, it's extremely easy to set up. Backup will provide
13
+ a generator script that will place all necessary files inside your Rails application.
14
+ Two of which, are “yaml” configuration files. Using just these two files to configure a
15
+ backup for database formats such as a MySQL, SQLite3 or any Assets folder.
16
+ Setting up “Backup” takes only about a minute or two!
17
+ }
18
+
12
19
  gem.email = "meskyan@gmail.com"
13
20
  gem.homepage = "http://github.com/meskyanichi/backup"
14
21
  gem.authors = ["meskyanichi"]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 1.0.0
data/backup.gemspec CHANGED
@@ -5,14 +5,20 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{backup}
8
- s.version = "0.2.0"
8
+ s.version = "1.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["meskyanichi"]
12
- s.date = %q{2009-10-03}
13
- s.description = %q{Backup is a gem/plugin that enables you to very easily create backups and transfer these to Amazon S3 or another server with SSH.
14
- It currently supports MySQL, SQLite3 and basic Assets (documents, images, etc). The files will get tar'd / gzip'd and get a timestamp.
15
- After creation, these files can be transferred to either Amazon S3 or any remote server through SSH.}
12
+ s.date = %q{2009-10-07}
13
+ s.description = %q{
14
+ “Backup” is a RubyGem, written for Ruby on Rails. It's main purpose is to Backup any
15
+ files to Amazon S3 or any remotely accessible server through SSH (SCP). It supports database
16
+ and regular file backups. On top of that, it's extremely easy to set up. Backup will provide
17
+ a generator script that will place all necessary files inside your Rails application.
18
+ Two of which, are “yaml” configuration files. Using just these two files to configure a
19
+ backup for database formats such as a MySQL, SQLite3 or any Assets folder.
20
+ Setting up “Backup” takes only about a minute or two!
21
+ }
16
22
  s.email = %q{meskyan@gmail.com}
17
23
  s.extra_rdoc_files = [
18
24
  "LICENSE",
@@ -26,10 +32,12 @@ Gem::Specification.new do |s|
26
32
  "Rakefile",
27
33
  "VERSION",
28
34
  "backup.gemspec",
29
- "generators/backup_rake_tasks/backup_rake_tasks_generator.rb",
30
- "generators/backup_rake_tasks/templates/README.rdoc",
31
- "generators/backup_rake_tasks/templates/s3.rake",
32
- "generators/backup_rake_tasks/templates/ssh.rake",
35
+ "generators/backup_tasks/backup_tasks_generator.rb",
36
+ "generators/backup_tasks/templates/config.rake",
37
+ "generators/backup_tasks/templates/s3.rake",
38
+ "generators/backup_tasks/templates/s3.yml",
39
+ "generators/backup_tasks/templates/ssh.rake",
40
+ "generators/backup_tasks/templates/ssh.yml",
33
41
  "lib/backup.rb",
34
42
  "lib/backup/assets.rb",
35
43
  "lib/backup/base.rb",
@@ -37,6 +45,7 @@ Gem::Specification.new do |s|
37
45
  "lib/backup/connection/s3.rb",
38
46
  "lib/backup/connection/ssh.rb",
39
47
  "lib/backup/custom.rb",
48
+ "lib/backup/encrypt.rb",
40
49
  "lib/backup/mysql.rb",
41
50
  "lib/backup/sqlite3.rb",
42
51
  "lib/backup/transfer/base.rb",
@@ -1,4 +1,4 @@
1
- class BackupRakeTasksGenerator < Rails::Generator::Base
1
+ class BackupTasksGenerator < Rails::Generator::Base
2
2
 
3
3
  # This method gets initialized when the generator gets run.
4
4
  # It will receive an array of arguments inside @args
@@ -13,11 +13,19 @@ class BackupRakeTasksGenerator < Rails::Generator::Base
13
13
  # This will automatically be run after the initialize method
14
14
  def manifest
15
15
  record do |m|
16
+
17
+ # Generate the Rake Tasks
16
18
  m.directory "lib/tasks/"
17
19
  m.directory "lib/tasks/backup"
18
- m.file "README.rdoc", "lib/tasks/backup/README.rdoc"
20
+ m.file "config.rake", "lib/tasks/backup/config.rake"
19
21
  m.file "s3.rake", "lib/tasks/backup/s3.rake"
20
22
  m.file "ssh.rake", "lib/tasks/backup/ssh.rake"
23
+
24
+ # Generate the YAML files
25
+ m.directory "config/backup"
26
+ m.file "s3.yml", "config/backup/s3.yml"
27
+ m.file "ssh.yml", "config/backup/ssh.yml"
28
+
21
29
  end
22
30
  end
23
31
 
@@ -0,0 +1,33 @@
1
+ namespace :backup do
2
+
3
+ task :s3_config => :environment do
4
+ @config = YAML.load_file(File.join(RAILS_ROOT, 'config', 'backup', 's3.yml'))
5
+
6
+ @config.each do |key, value|
7
+ value.each do |k, v|
8
+ if @config[key][k].is_a?(String)
9
+ @config[key][k] = @config[key][k][v].gsub(/:rails_root/, RAILS_ROOT)
10
+ end
11
+ if @config[key][k].is_a?(Array)
12
+ @config[key][k].map! {|string| string.gsub(/:rails_root/, RAILS_ROOT)}
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ task :ssh_config => :environment do
19
+ @config = YAML.load_file(File.join(RAILS_ROOT, 'config', 'backup', 'ssh.yml'))
20
+
21
+ @config.each do |key, value|
22
+ value.each do |k, v|
23
+ if @config[key][k].is_a?(String)
24
+ @config[key][k] = @config[key][k][v].gsub(/:rails_root/, RAILS_ROOT)
25
+ end
26
+ if @config[key][k].is_a?(Array)
27
+ @config[key][k].map! {|string| string.gsub(/:rails_root/, RAILS_ROOT)}
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ end
@@ -8,19 +8,23 @@ namespace :backup do
8
8
  # Specify which bucket you wish to store your files to.
9
9
  # If you wish to put specific files in subfolders inside the bucket, you may do so by doing something like this:
10
10
  # :bucket => "my_bucket/subfolder1/subfolder2" etc.
11
- task :mysql => :environment do
11
+ desc 'Makes a backup from a MySQL database and transfers it to Amazon S3.'
12
+ task :mysql => :s3_config do
13
+ @config = @config['mysql']
12
14
  Backup::Mysql.new({
13
15
  :mysql => {
14
- :user => "",
15
- :password => "",
16
- :database => ""
16
+ :user => @config['mysql_config']['user'],
17
+ :password => @config['mysql_config']['password'],
18
+ :database => @config['mysql_config']['database']
17
19
  },
18
20
 
21
+ :encrypt => @config['encrypt'],
22
+
19
23
  :use => :s3,
20
24
  :s3 => {
21
- :access_key_id => '',
22
- :secret_access_key => '',
23
- :bucket => 'mybucket/backups/etc'
25
+ :access_key_id => @config['s3']['access_key_id'],
26
+ :secret_access_key => @config['s3']['secret_access_key'],
27
+ :bucket => @config['s3']['bucket']
24
28
  }
25
29
  }).run
26
30
  end
@@ -32,15 +36,19 @@ namespace :backup do
32
36
  # Specify which bucket you wish to store your files to.
33
37
  # If you wish to put specific files in subfolders inside the bucket, you may do so by doing something like this:
34
38
  # :bucket => "my_bucket/subfolder1/subfolder2" etc.
35
- task :sqlite3 => :environment do
39
+ desc 'Makes a backup from a SQLite3 database and transfers it to Amazon S3.'
40
+ task :sqlite3 => :s3_config do
41
+ @config = @config['sqlite3']
36
42
  Backup::Sqlite3.new({
37
- :file => 'production.sqlite3', # "production.sqlite3" is default, can remove the whole :file attribute or change it's value
38
-
43
+ :file => @config['file'],
44
+ :path => @config['path'],
45
+ :encrypt => @config['encrypt'],
46
+
39
47
  :use => :s3,
40
48
  :s3 => {
41
- :access_key_id => '',
42
- :secret_access_key => '',
43
- :bucket => 'mybucket/backups/etc'
49
+ :access_key_id => @config['s3']['access_key_id'],
50
+ :secret_access_key => @config['s3']['secret_access_key'],
51
+ :bucket => @config['s3']['bucket']
44
52
  }
45
53
  }).run
46
54
  end
@@ -52,15 +60,18 @@ namespace :backup do
52
60
  # Specify which bucket you wish to store your files to.
53
61
  # If you wish to put specific files in subfolders inside the bucket, you may do so by doing something like this:
54
62
  # :bucket => "my_bucket/subfolder1/subfolder2" etc.
55
- task :assets => :environment do
63
+ desc 'Makes a backup from Assets and transfers it to Amazon S3.'
64
+ task :assets => :s3_config do
65
+ @config = @config['assets']
56
66
  Backup::Assets.new({
57
- :path => "#{RAILS_ROOT}/public/assets",
67
+ :path => @config['path'],
68
+ :encrypt => @config['encrypt'],
58
69
 
59
70
  :use => :s3,
60
71
  :s3 => {
61
- :access_key_id => '',
62
- :secret_access_key => '',
63
- :bucket => 'mybucket/backups/etc'
72
+ :access_key_id => @config['s3']['access_key_id'],
73
+ :secret_access_key => @config['s3']['secret_access_key'],
74
+ :bucket => @config['s3']['bucket']
64
75
  }
65
76
  }).run
66
77
  end
@@ -99,19 +110,20 @@ namespace :backup do
99
110
  #
100
111
  # Just use the ":use => :s3" as usual to tell it you would like to back up these files using S3.
101
112
  # And then, like in the example below, provide the S3 credentials/details to be able to connect to the server you wish to back these files up to.
102
- task :custom => :environment do
113
+ desc 'Makes a backup from a Custom database and transfers it to Amazon S3.'
114
+ task :custom => :s3_config do
115
+ @config = @config['custom']
103
116
  Backup::Custom.new({
104
- :command => ["mysqldump --quick -u root --password='' foobar > #{RAILS_ROOT}/db/foobar1.sql",
105
- "mysqldump --quick -u root --password='' foobar > #{RAILS_ROOT}/db/foobar2.sql"],
106
-
107
- :path => "#{RAILS_ROOT}/db",
108
- :file => ["foobar1.sql","foobar2.sql"],
117
+ :file => @config['file'],
118
+ :path => @config['path'],
119
+ :command => @config['command'],
120
+ :encrypt => @config['encrypt'],
109
121
 
110
122
  :use => :s3,
111
123
  :s3 => {
112
- :access_key_id => '',
113
- :secret_access_key => '',
114
- :bucket => 'mybucket/backups/etc'
124
+ :access_key_id => @config['s3']['access_key_id'],
125
+ :secret_access_key => @config['s3']['secret_access_key'],
126
+ :bucket => @config['s3']['bucket']
115
127
  }
116
128
  }).run
117
129
  end
@@ -0,0 +1,88 @@
1
+ # Backup Configuration file for "Amazon S3 Backups"
2
+ # This file was generated with the Backup Generator
3
+ #
4
+ # FOR MORE INFORMATION, VIEW THE WIKI ON GITHUB:
5
+ # http://wiki.github.com/meskyanichi/backup
6
+ #
7
+ # If you wish to make use of the Amazon S3 service to store your
8
+ # backups, use this configuration file.
9
+ #
10
+ # Step by Step
11
+ #
12
+ # Step 1
13
+ # Choose the adapter you would like to use to back up your files
14
+ # (MySQL, SQLite3, Assets or something Custom)
15
+ #
16
+ # Step 2
17
+ # Fill in the values for the adapter you choose.
18
+ # You do not need to fill in the values for every adapter,
19
+ # only the ones you are going to use. The rest you can leave untouched or remove.
20
+ #
21
+ # Step 3
22
+ # Once you've filled in all values, you are ready to execute the rake task that
23
+ # starts that backup process. Above each Adapter you will see what rake task should
24
+ # be run to start the backup process for that specific Adapter.
25
+ #
26
+ # Step 4
27
+ # Once set up, you could set these rake tasks up in a cronjob to execute it periodically.
28
+ # For handling this, I recommend using the javan-whenever gem
29
+ #
30
+ # See here: http://github.com/javan/whenever
31
+
32
+
33
+ # MySQL Adapter
34
+ # To run this adapter, execute the following rake task:
35
+ # rake backup:s3:mysql
36
+ mysql:
37
+ mysql_config:
38
+ user: root
39
+ password: ''
40
+ database: my_database
41
+ s3:
42
+ access_key_id: my_access_key_id
43
+ secret_access_key: my_secret_access_key
44
+ bucket: my_bucket
45
+ #encrypt: my_secret_password # Uncomment me if you want to encrypt the backup
46
+
47
+
48
+ # SQLite3 Adapter
49
+ # To run this adapter, execute the following rake task:
50
+ # rake backup:s3:sqlite3
51
+ sqlite3:
52
+ file: production.sqlite3
53
+ path: ':rails_root/db'
54
+ s3:
55
+ access_key_id: my_access_key_id
56
+ secret_access_key: my_secret_access_key
57
+ bucket: my_bucket
58
+ #encrypt: my_secret_password # Uncomment me if you want to encrypt the backup
59
+
60
+
61
+ # Asset Adapter
62
+ # To run this adapter, execute the following rake task:
63
+ # rake backup:s3:assets
64
+ assets:
65
+ path: ':rails_root/public/assets'
66
+ s3:
67
+ access_key_id: my_access_key_id
68
+ secret_access_key: my_secret_access_key
69
+ bucket: my_bucket
70
+ #encrypt: my_secret_password # Uncomment me if you want to encrypt the backup
71
+
72
+
73
+ # Custom Adapter
74
+ # To run this adapter, execute the following rake task:
75
+ # rake backup:s3:custom
76
+ custom:
77
+ path: ':rails_root/db'
78
+ file:
79
+ - 'foobar1.sql'
80
+ - 'foobar2.sql'
81
+ command:
82
+ - 'mysqldump --quick -u root --password="" foobar > :rails_root/db/foobar1.sql'
83
+ - 'mysqldump --quick -u root --password="" foobar > :rails_root/db/foobar2.sql'
84
+ s3:
85
+ access_key_id: my_access_key_id
86
+ secret_access_key: my_secret_access_key
87
+ bucket: my_bucket
88
+ #encrypt: my_secret_password # Uncomment me if you want to encrypt the backup
@@ -6,38 +6,46 @@ namespace :backup do
6
6
  # Specify that you want to use :ssh
7
7
  # Specify what user should connect through SSH, to what address (be it IP or an URL) and the absolute path on the backup-server
8
8
  # to where Backup should store the backups.
9
- task :mysql => :environment do
9
+ desc 'Makes a backup from a MySQL database and transfers it through SSH (SCP).'
10
+ task :mysql => :ssh_config do
11
+ @config = @config['mysql']
10
12
  Backup::Mysql.new({
11
13
  :mysql => {
12
- :user => "",
13
- :password => "",
14
- :database => ""
14
+ :user => @config['mysql_config']['user'],
15
+ :password => @config['mysql_config']['password'],
16
+ :database => @config['mysql_config']['database']
15
17
  },
16
18
 
19
+ :encrypt => @config['encrypt'],
20
+
17
21
  :use => :ssh,
18
22
  :ssh => {
19
- :user => "root",
20
- :ip => "mydomain.com", # or: 123.45.678.90
21
- :path => "/var/backups/etc"
23
+ :user => @config['ssh']['user'],
24
+ :ip => @config['ssh']['ip'],
25
+ :path => @config['ssh']['path']
22
26
  }
23
27
  }).run
24
28
  end
25
-
29
+
26
30
  # => rake backup:ssh:sqlite3
27
31
  # Specify which sqlite3 file you wish to back up. This will generally be "production.sqlite3". (and this is the default, so you can remove the :file attribute if it is)
28
32
  # If your sqlite3 file is not located inside the #{RAILS_ROOT}/db folder, then add a :path => "#{RAILS_ROOT}/path/to/db/folder"
29
33
  # Specify that you want to use :ssh
30
34
  # Specify what user should connect through SSH, to what address (be it IP or an URL) and the absolute path on the backup-server
31
35
  # to where Backup should store the backups.
32
- task :sqlite3 => :environment do
36
+ desc 'Makes a backup from a SQLite3 database and transfers it through SSH (SCP).'
37
+ task :sqlite3 => :ssh_config do
38
+ @config = @config['sqlite3']
33
39
  Backup::Sqlite3.new({
34
- :file => 'production.sqlite3', # "production.sqlite3" is default, can remove the whole :file attribute or change it's value
40
+ :file => @config['file'],
41
+ :path => @config['path'],
42
+ :encrypt => @config['encrypt'],
35
43
 
36
44
  :use => :ssh,
37
45
  :ssh => {
38
- :user => "root",
39
- :ip => "mydomain.com", # or: 123.45.678.90
40
- :path => "/var/backups/etc"
46
+ :user => @config['ssh']['user'],
47
+ :ip => @config['ssh']['ip'],
48
+ :path => @config['ssh']['path']
41
49
  }
42
50
  }).run
43
51
  end
@@ -47,15 +55,18 @@ namespace :backup do
47
55
  # Specify that you want to use :ssh
48
56
  # Specify what user should connect through SSH, to what address (be it IP or an URL) and the absolute path on the backup-server
49
57
  # to where Backup should store the backups.
50
- task :assets => :environment do
58
+ desc 'Makes a backup from Assets and transfers it through SSH (SCP).'
59
+ task :assets => :ssh_config do
60
+ @config = @config['assets']
51
61
  Backup::Assets.new({
52
- :path => "#{RAILS_ROOT}/public/assets",
62
+ :path => @config['path'],
63
+ :encrypt => @config['encrypt'],
53
64
 
54
65
  :use => :ssh,
55
66
  :ssh => {
56
- :user => "root",
57
- :ip => "mydomain.com", # or: 123.45.678.90
58
- :path => "/var/backups/etc"
67
+ :user => @config['ssh']['user'],
68
+ :ip => @config['ssh']['ip'],
69
+ :path => @config['ssh']['path']
59
70
  }
60
71
  }).run
61
72
  end
@@ -94,19 +105,20 @@ namespace :backup do
94
105
  #
95
106
  # Just use the ":use => :ssh" as usual to tell it you would like to back up these files using SSH.
96
107
  # And then, like in the example below, provide the SSH details to be able to connect to the server you wish to back these files up to.
97
- task :custom => :environment do
108
+ desc 'Makes a backup from a Custom database and transfers it through SSH (SCP).'
109
+ task :custom => :ssh_config do
110
+ @config = @config['custom']
98
111
  Backup::Custom.new({
99
- :command => ["mysqldump --quick -u root --password='' foobar > #{RAILS_ROOT}/db/foobar1.sql",
100
- "mysqldump --quick -u root --password='' foobar > #{RAILS_ROOT}/db/foobar2.sql"],
101
-
102
- :path => "#{RAILS_ROOT}/db",
103
- :file => ["foobar1.sql", "foobar2.sql"],
112
+ :file => @config['file'],
113
+ :path => @config['path'],
114
+ :command => @config['command'],
115
+ :encrypt => @config['encrypt'],
104
116
 
105
117
  :use => :ssh,
106
118
  :ssh => {
107
- :user => "root",
108
- :ip => "mydomain.com", # or: 123.45.678.90
109
- :path => "/var/backups/etc"
119
+ :user => @config['ssh']['user'],
120
+ :ip => @config['ssh']['ip'],
121
+ :path => @config['ssh']['path']
110
122
  }
111
123
  }).run
112
124
  end
@@ -0,0 +1,88 @@
1
+ # Backup Configuration file for "SSH (SCP) Backups"
2
+ # This file was generated with the Backup Generator
3
+ #
4
+ # FOR MORE INFORMATION, VIEW THE WIKI ON GITHUB:
5
+ # http://wiki.github.com/meskyanichi/backup
6
+ #
7
+ # If you wish to make use of SSH (SCP) to store your
8
+ # backups to another server, use this configuration file.
9
+ #
10
+ # Step by Step
11
+ #
12
+ # Step 1
13
+ # Choose the adapter you would like to use to back up your files
14
+ # (MySQL, SQLite3, Assets or something Custom)
15
+ #
16
+ # Step 2
17
+ # Fill in the values for the adapter you choose.
18
+ # You do not need to fill in the values for every adapter,
19
+ # only the ones you are going to use. The rest you can leave untouched or remove.
20
+ #
21
+ # Step 3
22
+ # Once you've filled in all values, you are ready to execute the rake task that
23
+ # starts that backup process. Above each Adapter you will see what rake task should
24
+ # be run to start the backup process for that specific Adapter.
25
+ #
26
+ # Step 4
27
+ # Once set up, you could set these rake tasks up in a cronjob to execute it periodically.
28
+ # For handling this, I recommend using the javan-whenever gem
29
+ #
30
+ # See here: http://github.com/javan/whenever
31
+
32
+
33
+ # MySQL Adapter
34
+ # To run this adapter, execute the following rake task:
35
+ # rake backup:ssh:mysql
36
+ mysql:
37
+ mysql_config:
38
+ user: root
39
+ password: ''
40
+ database: foobar
41
+ ssh:
42
+ user: root
43
+ ip: my-domain.com
44
+ path: '/var/backups'
45
+ #encrypt: my_secret_password # Uncomment me if you want to encrypt the backup
46
+
47
+
48
+ # SQLite3 Adapter
49
+ # To run this adapter, execute the following rake task:
50
+ # rake backup:ssh:sqlite3
51
+ sqlite3:
52
+ file: production.sqlite3
53
+ path: ':rails_root/db'
54
+ ssh:
55
+ user: root
56
+ ip: my-domain.com
57
+ path: '/var/backups'
58
+ #encrypt: my_secret_password # Uncomment me if you want to encrypt the backup
59
+
60
+
61
+ # Asset Adapter
62
+ # To run this adapter, execute the following rake task:
63
+ # rake backup:ssh:assets
64
+ assets:
65
+ path: ':rails_root/public/assets'
66
+ ssh:
67
+ user: root
68
+ ip: my-domain.com
69
+ path: '/var/backups'
70
+ #encrypt: my_secret_password # Uncomment me if you want to encrypt the backup
71
+
72
+
73
+ # Custom Adapter
74
+ # To run this adapter, execute the following rake task:
75
+ # rake backup:ssh:custom
76
+ custom:
77
+ path: ':rails_root/db'
78
+ file:
79
+ - 'foobar1.sql'
80
+ - 'foobar2.sql'
81
+ command:
82
+ - 'mysqldump --quick -u root --password="" foobar1 > :rails_root/db/foobar1.sql'
83
+ - 'mysqldump --quick -u root --password="" foobar2 > :rails_root/db/foobar2.sql'
84
+ ssh:
85
+ user: root
86
+ ip: my-domain.com
87
+ path: '/var/backups'
88
+ #encrypt: my_secret_password # Uncomment me if you want to encrypt the backup
data/lib/backup.rb CHANGED
@@ -3,6 +3,7 @@ require 'backup/sqlite3'
3
3
  require 'backup/mysql'
4
4
  require 'backup/assets'
5
5
  require 'backup/custom'
6
+ require 'backup/encrypt'
6
7
  require 'backup/transfer/base'
7
8
  require 'backup/transfer/s3'
8
9
  require 'backup/transfer/ssh'
data/lib/backup/assets.rb CHANGED
@@ -13,6 +13,8 @@ module Backup
13
13
  # Archives the specified folder to a .tar
14
14
  # - Compress
15
15
  # Compresses the .tar file using Gzip
16
+ # - Encrypt
17
+ # Encrypts the backup file
16
18
  # - Transfer
17
19
  # Initializes the transfer to either S3 or using SSH
18
20
  # - Remove Temp Files
@@ -20,6 +22,7 @@ module Backup
20
22
  def run
21
23
  archive
22
24
  compress
25
+ encrypt
23
26
  transfer
24
27
  remove_temp_files
25
28
  end
data/lib/backup/base.rb CHANGED
@@ -38,6 +38,17 @@ module Backup
38
38
  end
39
39
  end
40
40
 
41
+ # Encrypts the backup file
42
+ # Only if the encrypt option is specified inside the .yml config file
43
+ # Otherwise, the encryption will be not be executed.
44
+ # Encryption is OPTIONAL.
45
+ def encrypt
46
+ unless options[:encrypt].blank?
47
+ Backup::Encrypt.new(options).run
48
+ options[:backup_file] = "#{options[:backup_file]}.enc"
49
+ end
50
+ end
51
+
41
52
  # Removes files that were stored in the tmp/backups/* directory of the Rails application
42
53
  # It completely cleans up the backup folders so theres no trash stored on the production server
43
54
  def remove_temp_files
@@ -48,12 +59,14 @@ module Backup
48
59
  # This can remove either a single file or an array of files
49
60
  # Depending on whether the options[:file] is an Array or a String
50
61
  def remove_original_file
51
- if options[:file].is_a?(Array)
52
- options[:file].each do |file|
53
- %x{ rm #{File.join(options[:path], file)} }
62
+ unless options[:keep_original_files].eql?(true)
63
+ if options[:file].is_a?(Array)
64
+ options[:file].each do |file|
65
+ %x{ rm #{File.join(options[:path], file)} }
66
+ end
67
+ else
68
+ %x{ rm #{File.join(options[:path], options[:file])} }
54
69
  end
55
- else
56
- %x{ rm #{File.join(options[:path], options[:file])} }
57
70
  end
58
71
  end
59
72
 
data/lib/backup/custom.rb CHANGED
@@ -15,6 +15,8 @@ module Backup
15
15
  # Archives the specified folder to a .tar
16
16
  # - Compress
17
17
  # Compresses the .tar file using Gzip
18
+ # - Encrypt
19
+ # Encrypts the backup file
18
20
  # - Transfer
19
21
  # Initializes the transfer to either S3 or using SSH
20
22
  # - Remove Temp Files
@@ -25,9 +27,10 @@ module Backup
25
27
  command
26
28
  archive
27
29
  compress
30
+ encrypt
28
31
  transfer
29
32
  remove_temp_files
30
- remove_original_file unless options[:keep_original_files].eql?(true)
33
+ remove_original_file
31
34
  end
32
35
 
33
36
  private
@@ -0,0 +1,18 @@
1
+ module Backup
2
+ class Encrypt
3
+
4
+ attr_accessor :options
5
+
6
+ def initialize(options = {})
7
+ self.options = options
8
+ end
9
+
10
+ # Encrypts the backup file
11
+ def run
12
+ unencrypted_file = File.join(options[:backup_path], options[:backup_file])
13
+ encrypted_file = File.join(options[:backup_path], options[:backup_file] + '.enc')
14
+ %x{ openssl enc -des-cbc -in #{unencrypted_file} -out #{encrypted_file} -k #{options[:encrypt]} }
15
+ end
16
+
17
+ end
18
+ end
data/lib/backup/mysql.rb CHANGED
@@ -13,6 +13,8 @@ module Backup
13
13
  # Creates a MySQL dump based on the parameters provided by the user
14
14
  # - Compress
15
15
  # Compresses the .tar file using Gzip
16
+ # - Encrypt
17
+ # Encrypts the backup file
16
18
  # - Transfer
17
19
  # Initializes the transfer to either S3 or using SSH
18
20
  # - Remove Temp Files
@@ -20,6 +22,7 @@ module Backup
20
22
  def run
21
23
  make_mysql_dump
22
24
  compress
25
+ encrypt
23
26
  transfer
24
27
  remove_temp_files
25
28
  end
@@ -11,12 +11,15 @@ module Backup
11
11
  #
12
12
  # - Compress
13
13
  # Compresses the .tar file using Gzip
14
+ # - Encrypt
15
+ # Encrypts the backup file
14
16
  # - Transfer
15
17
  # Initializes the transfer to either S3 or using SSH
16
18
  # - Remove Temp Files
17
19
  # Removes temporary files after the process is complete
18
20
  def run
19
21
  compress
22
+ encrypt
20
23
  transfer
21
24
  remove_temp_files
22
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - meskyanichi
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-03 00:00:00 +02:00
12
+ date: 2009-10-07 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,10 +22,7 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: "0"
24
24
  version:
25
- description: |-
26
- Backup is a gem/plugin that enables you to very easily create backups and transfer these to Amazon S3 or another server with SSH.
27
- It currently supports MySQL, SQLite3 and basic Assets (documents, images, etc). The files will get tar'd / gzip'd and get a timestamp.
28
- After creation, these files can be transferred to either Amazon S3 or any remote server through SSH.
25
+ description: "\n \xE2\x80\x9CBackup\xE2\x80\x9D is a RubyGem, written for Ruby on Rails. It's main purpose is to Backup any\n files to Amazon S3 or any remotely accessible server through SSH (SCP). It supports database\n and regular file backups. On top of that, it's extremely easy to set up. Backup will provide\n a generator script that will place all necessary files inside your Rails application.\n Two of which, are \xE2\x80\x9Cyaml\xE2\x80\x9D configuration files. Using just these two files to configure a\n backup for database formats such as a MySQL, SQLite3 or any Assets folder.\n Setting up \xE2\x80\x9CBackup\xE2\x80\x9D takes only about a minute or two!\n "
29
26
  email: meskyan@gmail.com
30
27
  executables: []
31
28
 
@@ -42,10 +39,12 @@ files:
42
39
  - Rakefile
43
40
  - VERSION
44
41
  - backup.gemspec
45
- - generators/backup_rake_tasks/backup_rake_tasks_generator.rb
46
- - generators/backup_rake_tasks/templates/README.rdoc
47
- - generators/backup_rake_tasks/templates/s3.rake
48
- - generators/backup_rake_tasks/templates/ssh.rake
42
+ - generators/backup_tasks/backup_tasks_generator.rb
43
+ - generators/backup_tasks/templates/config.rake
44
+ - generators/backup_tasks/templates/s3.rake
45
+ - generators/backup_tasks/templates/s3.yml
46
+ - generators/backup_tasks/templates/ssh.rake
47
+ - generators/backup_tasks/templates/ssh.yml
49
48
  - lib/backup.rb
50
49
  - lib/backup/assets.rb
51
50
  - lib/backup/base.rb
@@ -53,6 +52,7 @@ files:
53
52
  - lib/backup/connection/s3.rb
54
53
  - lib/backup/connection/ssh.rb
55
54
  - lib/backup/custom.rb
55
+ - lib/backup/encrypt.rb
56
56
  - lib/backup/mysql.rb
57
57
  - lib/backup/sqlite3.rb
58
58
  - lib/backup/transfer/base.rb
@@ -1,25 +0,0 @@
1
- * Backup's Generated Rake Tasks
2
- http://github.com/meskyanichi/backup
3
-
4
- Quite simple, the generator has now generated all (currently!) possible backup options in the form of rake tasks!
5
- Just open the desired backup-method's file (S3 or SHH or BOTH!). The basic structure of every task is already setup correctly.
6
- Above each task you will find a description about the settings of each task. Please be sure to read this first before asking questions.
7
-
8
- All in all this is extremely straight forward, there is no need to setup anything else inside your Rails Application other than installing the plugin,
9
- running (this) generator and changing the values inside the rake task files.
10
-
11
- Here is a list of the current rake tasks that are available:
12
-
13
- backup:s3:mysql
14
- backup:s3:sqlite3
15
- backup:s3:assets
16
- backup:s3:custom
17
- backup:ssh:mysql
18
- backup:ssh:sqlite3
19
- backup:ssh:assets
20
- backup:ssh:custom
21
-
22
-
23
- So now you have rake tasks for all your essential backups.
24
- What I like to do is use a cronjob manager gem to manage my cronjobs to trigger these rake tasks.
25
- javan-whenever is a good gem for doing this! Try it, or any other method you can think of to trigger these rake tasks periodically.