aurels-backuper 0.2 → 0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. data/README.rdoc +26 -0
  2. data/examples/backup.rb +71 -0
  3. data/lib/backuper.rb +7 -5
  4. metadata +4 -3
  5. data/README +0 -14
@@ -0,0 +1,26 @@
1
+ A simple server backup tool written in Ruby.
2
+
3
+ = To install:
4
+
5
+ sudo gem source -a http://gems.github.com
6
+ sudo gem install aurels-backuper
7
+
8
+ = Dependencies:
9
+
10
+ UNIX commands:
11
+ - 'tar'
12
+ - 'mysqldump' if you want to backup your MySQL databases
13
+ - 'ncftpput' if you backup through FTP
14
+ - 'scp' if you backup through SSH
15
+
16
+ = To use:
17
+
18
+ - Create a script file which requires 'backuper' and create a new Backuper instance
19
+ - Configure cron to run the script as root when you want
20
+
21
+ An example of backup script is in examples/backup.rb (use it as a base template).
22
+
23
+ (c) 2009 Aurélien Malisart, aurelien.malisart@gmail.com, http://aurelien.malisart.be
24
+
25
+ Released under GNU GPLv3 license.
26
+
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'rubygems'
4
+ require 'backuper'
5
+
6
+ ################################################################################
7
+
8
+ backup = Backuper.new
9
+
10
+ # Unix general =================================================================
11
+
12
+ backup.config_file "/etc/ssh/sshd_config"
13
+ backup.config_file "/etc/passwd"
14
+ backup.config_file "/etc/group"
15
+ backup.config_file "/etc/contab"
16
+
17
+ # Apache2 ======================================================================
18
+
19
+ backup.config_file "/etc/apache2/httpd.conf"
20
+ backup.config_dir "/etc/apache2/sites-available"
21
+
22
+ # Nginx ========================================================================
23
+
24
+ backup.config_file "/opt/nginx/conf/nginx.conf"
25
+ backup.config_dir "/opt/nginx/conf/sites-available"
26
+
27
+ # SQLite databases =============================================================
28
+
29
+ backup.sqlite_database "/home/aurels/databases/espassvie.sqlite3"
30
+
31
+ # MySQL databases ==============================================================
32
+
33
+ backup.mysql_params = {
34
+ :user => 'backup',
35
+ :password => 'blup'
36
+ }
37
+
38
+ # We recommend creating a 'backup' user with only SELECT and LOCK TABLES
39
+ # privileges :
40
+ #
41
+ # mysql -u root -p
42
+ # GRANT SELECT, LOCK TABLES ON *.* TO backup@localhost IDENTIFIED BY 'blup';
43
+ # FLUSH PRIVILEGES;
44
+
45
+ backup.mysql_database 'db1'
46
+ backup.mysql_database 'db2'
47
+
48
+ # Data directories =============================================================
49
+
50
+ backup.data_dir "/super/projet/rails/public/assets"
51
+
52
+ # FTP or SSH setup =============================================================
53
+
54
+ backup.ftp_params = {
55
+ :host => '',
56
+ :user => '',
57
+ :password => '',
58
+ :path => '/backups' # path on host
59
+ }
60
+
61
+ # or:
62
+
63
+ #backup.ssh_params = {
64
+ # :host => '',
65
+ # :user => '', # this user needs to have his public key authorized on the host
66
+ # :path => '/home/aurels/backups' # path on host
67
+ #}
68
+
69
+ ################################################################################
70
+
71
+ backup.perform!
@@ -1,9 +1,10 @@
1
1
  class Backuper
2
2
 
3
- TMP_DIR = "/backuper"
3
+ TMP_DIR = "/tmp/backuper"
4
4
 
5
5
  attr_writer :mysql_params
6
6
  attr_writer :ftp_params
7
+ attr_writer :ssh_params
7
8
 
8
9
  def initialize
9
10
  @config_files = []
@@ -13,6 +14,7 @@ class Backuper
13
14
  @mysql_databases = []
14
15
  @data_dirs = []
15
16
  @ftp_params = {}
17
+ @ssh_params = {}
16
18
  @archive_filename = "backup-#{Time.now.strftime('%Y-%m-%d')}-#{Time.now.to_i}.tar.gz"
17
19
  end
18
20
 
@@ -76,8 +78,6 @@ class Backuper
76
78
  @mysql_databases.each do |db|
77
79
  run "mysqldump #{db} --user=#{@mysql_params[:user]} --password=#{@mysql_params[:password]} > #{File.join(TMP_DIR, 'databases', 'mysql', "#{db}.sql")}"
78
80
  end
79
- else
80
- say "MySQL databases backup not done because MySQL params are unset"
81
81
  end
82
82
  end
83
83
 
@@ -88,8 +88,10 @@ class Backuper
88
88
  def upload_archive
89
89
  unless @ftp_params.empty?
90
90
  run "ncftpput -u #{@ftp_params[:user]} -p #{@ftp_params[:password]} #{@ftp_params[:host]} #{@ftp_params[:path]} /tmp/#{@archive_filename}"
91
- else
92
- say "Upload to FTP server not done because FTP params are unset"
91
+ end
92
+
93
+ unless @ssh_params.empty?
94
+ run "scp /tmp/#{@archive_filename} #{@ssh_params[:user]}@#{@ssh_params[:host]}:#{@ssh_params[:path]}"
93
95
  end
94
96
  end
95
97
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aurels-backuper
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.2"
4
+ version: "0.3"
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Aur\xC3\xA9lien Malisart"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-22 00:00:00 -07:00
12
+ date: 2009-07-25 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -22,8 +22,9 @@ extensions: []
22
22
  extra_rdoc_files: []
23
23
 
24
24
  files:
25
- - README
25
+ - README.rdoc
26
26
  - lib/backuper.rb
27
+ - examples/backup.rb
27
28
  has_rdoc: false
28
29
  homepage: http://github.com/aurels/backuper
29
30
  post_install_message:
data/README DELETED
@@ -1,14 +0,0 @@
1
- A simple server backup tool written in Ruby.
2
-
3
- To install:
4
-
5
- sudo gem list -a http://gems.github.com
6
- sudo gem install aurels-backuper
7
-
8
- To use:
9
-
10
- - Create a script file which requires 'backuper' and create a new Backuper instance
11
- - Configure cron to run the script as root when you want
12
-
13
- Example of backup script in examples/backup.rb (use it as a base template)
14
-