rtbackup 0.1.21 → 0.1.22

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 212b6a678d4e7dd3153fe755cf6b87a13cbe51a7
4
- data.tar.gz: 9f6a0e378d592e3d176cbe43c3c468205c6f678d
3
+ metadata.gz: 9975ae069942cae2beab8186b5b78a22f23a1b70
4
+ data.tar.gz: 6556a498a682cdf0da406fe991fd689d76f68c2d
5
5
  SHA512:
6
- metadata.gz: 37b4351eda5c87677080a75d3ad039f09143fb73e61b39ab1ba957edfc5feb45f08742436c411aa3fd9920ba04fb46353edc6faef4054856190b7e06e90dc9c3
7
- data.tar.gz: 637e3a49d44b4a5b1485c150b119b5169c9c9abc37553687760eb7b4c34f3e84bfb0edb41b227eab21820def3daace3f562c197754856e554b50f2bf453d8159
6
+ metadata.gz: 12e3b1c4abbfcec96872e6eed291396f629687ba4321887e4cfd9276dcb04b1ecd92acc0ceeb8519a2474502aa4fee04608f901019dd47fb3bb9ca503fcd7140
7
+ data.tar.gz: b67153abaa09eaaa1d46d23cb602e313471ceecdd9c70b76fa116833df24785637a3ab65b59c01cf1e4f259409fbf5e48af4c093368a953630cc7d9a921e4c12
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- server_backups (0.1.21)
4
+ rtbackup (0.1.21)
5
5
  activesupport (~> 5.1)
6
6
  aws-sdk-s3 (~> 1.8)
7
7
  main (~> 6.2)
@@ -81,7 +81,7 @@ DEPENDENCIES
81
81
  bundler (~> 1.16)
82
82
  rake (~> 10.5)
83
83
  rspec (~> 3.0)
84
- server_backups!
84
+ rtbackup!
85
85
  vcr (~> 4.0)
86
86
  webmock (~> 3.3)
87
87
 
data/README.md CHANGED
@@ -17,28 +17,46 @@ to a given point in time.
17
17
 
18
18
  ## Installation
19
19
 
20
- Download the installation package from https://gitlab.com/zigzagau/server_backups/tags
21
- Find the latest tag and download server_backups-0.x.x.gem from there.
22
- Copy that file to your server.
20
+ ### Alpine Linux
21
+
22
+ The following instructions work for Alpine Linux
23
+
24
+ ```bash
25
+ apk add --no-cache ruby ruby-rake ruby-io-console ruby-bigdecimal ruby-json ruby-bundler \
26
+ tar gzip zlib zlib-dev dcron tzdata
27
+
28
+ cat > ~/.gemrc <<EOF
29
+ ---
30
+ gem: --no-ri --no-rdoc
31
+ EOF
32
+
33
+ gem install rtbackup
34
+
35
+ ```
23
36
 
24
37
  ### Ubuntu
25
38
 
26
39
  ```bash
27
40
 
28
- sudo apt install ruby ruby-dev zlib1g-dev
29
- sudo gem install server_backups-0.x.x.gem
41
+ sudo apt-get install -y ruby ruby-dev zlib1g-dev
42
+ sudo gem install rtbackup
30
43
 
31
44
  ```
32
45
 
33
- ### Configure Mysql Bin Logging
46
+ ### Configure Mysql Binary Logging
47
+
48
+ Make sure that binary logging is enabled on your mysql server. The following settings
49
+ need to be enabled in mysql configuration files. On Debian-based Linux distros this
50
+ means editing `/etc/mysql/mysql.conf.d/mysqld.cnf`, though Alpine Linux and others will
51
+ involve editing `/etc/mysql/my.cnf`.
34
52
 
35
- Add the following to your `my.cnf`, or on Ubuntu you might want to add it to `/etc/mysql/mysql.conf.d/mysqld.conf`
36
53
  ```
37
54
  [mysqld]
38
- ...
39
- server-id = 1 # Set it nicely if using replication
40
- log_bin = /var/log/mysql/mysql-bin.log # Or your favorite location
41
-
55
+ # ...
56
+ # Make sure that you know how to use this setting properly if you're using replication.
57
+ server-id = 1
58
+ log_bin = /var/log/mysql/mysql-bin # Make sure this matches the
59
+ # bin_log setting in your backup_conf.yml file.
42
60
  ```
43
61
 
44
62
  Then restart mysql:
@@ -55,43 +73,46 @@ sudo usermod -a -G www-data ubuntu
55
73
  sudo usermod -a -G mysql ubuntu
56
74
  ```
57
75
 
58
- ###
76
+ ## Set up backup_conf.yml
77
+
78
+ Set up a configuration file with the following command:
59
79
 
60
- ## Usage
80
+ ```bash
81
+ rtbackup create_config
82
+ ```
61
83
 
62
- ### Set up a configuration file
84
+ Now edit `~/.backup_conf.yml` and adjust it to fit your app's needs.
63
85
 
64
- Copy `backup_conf.sample.yml` to `~/.backup_conf.yml` and edit the settings.
65
- Alternatively you can put the file anywhere, and then specify the path to the file
66
- using the `-c` parameter, or even pipe a config file in through stdin.
86
+ ## Schedule backups to run.
67
87
 
68
- The latter option is useful if you'd like to keep passwords and keys in variables,
69
- rather than saving them to the filesystem.
88
+ Schedule your backups by running
70
89
 
71
90
  ```bash
72
- envsubst < back_conf.yml.tmpl | server_backup daily -c -
91
+ rtbackup crontab
73
92
  ```
74
93
 
75
- ### Set up your crontab.
94
+ This will enable the recommended backup schedule:
76
95
 
77
- * Use `crontab -e` to edit cron configuration.
96
+ * Hourly incremental backups from 1am to 11pm
97
+ * Daily full backups at midnight
98
+ * Weekly full backups on Sunday
99
+ * Monthly full backups on the first of the month
78
100
 
79
- **Sample Crontab configuration**
101
+ Full backups are all the same, but their retention periods differ.
80
102
 
103
+ Change the schedule by running the command:
104
+
105
+ ```bash
106
+ crontab -e
81
107
  ```
82
108
 
83
- # Once per month:
84
- 3 0 1 * * /usr/local/bin/server_backup monthly
85
- # Once per week:
86
- 5 0 * * 0 /usr/local/bin/server_backup weekly
87
- # Once per day:
88
- 5 0 * * 1-6 /usr/local/bin/server_backup daily
89
- # And incremental backups once per hour
90
- 5 1-23 * * * /usr/local/bin/server_backup incremental
109
+ See the [crontab manual pages](https://linux.die.net/man/5/crontab) or look online for tutorials
110
+ on how to edit cron schedules.
91
111
 
92
- ```
112
+ That's all! Your backups are now scheduled. You may run `rtbackup daily` in order to get your first
113
+ full backup.
93
114
 
94
- ### Command line parameters
115
+ # Command line parameters
95
116
 
96
117
  #### 1) For taking backups:
97
118
 
@@ -99,36 +120,36 @@ some examples
99
120
 
100
121
  ```bash
101
122
  # Take a full backup and store it in the monthly backups location.
102
- server_backup monthly
123
+ rtbackup monthly
103
124
 
104
125
  # Take a full backup as normal, but instead of backing up all databases,
105
126
  # only back up `mydatabase`.
106
- server_backup daily -d mydatabase
127
+ rtbackup daily -d mydatabase
107
128
 
108
- server_backup daily -f # only back up the files, not the database(s)
109
- server_backup daily -b # only back up the database(s), not the files
129
+ rtbackup daily -f # only back up the files, not the database(s)
130
+ rtbackup daily -b # only back up the database(s), not the files
110
131
 
111
132
  # Take an incremental backup, but load the given configuration file.
112
- server_backup incremental -c /etc/my_backup_configuration.cnf
133
+ rtbackup incremental -c /etc/my_backup_configuration.cnf
113
134
 
114
135
  ```
115
136
 
116
137
  #### 2) List (or search) time zones for help with configuration
117
138
 
118
139
  ```bash
119
- server_backup zones # list all
120
- server_backup zones america # case insensitive search for zones containing a string
140
+ rtbackup zones # list all
141
+ rtbackup zones america # case insensitive search for zones containing a string
121
142
  ```
122
143
 
123
144
  #### 3) Restore backups
124
145
 
125
146
  ```bash
126
147
  # Restore up to the latest backup data available on s3
127
- server_backup restore
148
+ rtbackup restore
128
149
 
129
150
  # Restore up to two days ago at 3pm in the configured
130
151
  # time zone (see config file).
131
- server_backup restore --up_to='two days ago at 3:00 PM'
152
+ rtbackup restore --up_to='two days ago at 3:00 PM'
132
153
 
133
154
  # To make it easier to decide what time your restore point
134
155
  # should be, you can write the restore point time in any time
@@ -138,16 +159,16 @@ server_backup restore --up_to='two days ago at 3:00 PM'
138
159
  # don't necessarily have to do any confusing time maths in order
139
160
  # to restore back to what time it was before you made a mistake
140
161
  # and updated a wordpress plugin. ;)
141
- server_backup restore --up_to='March 28 12:00 PM' --time_zone='Singapore'
162
+ rtbackup restore --up_to='March 28 12:00 PM' --time_zone='Singapore'
142
163
 
143
164
  ```
144
165
 
145
166
  ```
146
167
  NAME
147
- server_backup
168
+ rtbackup
148
169
 
149
170
  SYNOPSIS
150
- server_backup (restore|zones) backup_type [options]+
171
+ rtbackup (restore|zones) backup_type [options]+
151
172
 
152
173
  PARAMETERS
153
174
  backup_type (1 -> symbol(backup_type))
@@ -0,0 +1,11 @@
1
+ ## Alternate configuration options
2
+
3
+ Alternatively you can put the file anywhere, and then specify the path to the file
4
+ using the `-c` parameter, or even pipe a config file in through stdin.
5
+
6
+ The latter option is useful if you'd like to keep passwords and keys in variables,
7
+ rather than saving them to the filesystem.
8
+
9
+ ```bash
10
+ envsubst < back_conf.yml.tmpl | rtbackup daily -c -
11
+ ```
@@ -1,31 +1,59 @@
1
1
  ###############################################################################
2
2
  #
3
- # Sample Backup Configuration
4
- #
5
- #
3
+ # Sample RT Backup Config File
6
4
  #
7
5
  ###############################################################################
8
6
 
7
+ mysql:
8
+ host: 127.0.0.1
9
+ # Database to back up
10
+ database:
11
+ # MySql credentials
12
+ user: root
13
+ password:
14
+ # Path (with trailing slash) to mysql commands e.g. mysqldump
15
+ bin_path: /usr/bin/
16
+ # If you are using MySql binary logging:
17
+ # Path to the binary logs, should match the log_bin option in your my.cnf.
18
+ # Comment out if you are not using mysql binary logging
19
+ bin_log: /var/lib/mysql/mysql-bin
20
+
21
+ s3:
22
+ # S3 credentials
23
+ access_key_id: ASDFASDFASDFASDFASDF
24
+ secret_access_key: asdfasdfasdfasdfasdfasdfasdfasdfasdfasdf
25
+ # Bucket in which to store your backups
26
+ # # Bucket in which to store your backups
27
+ bucket: mycompany-wpbackups
28
+
29
+ # The prefix under which to store and retrieve backups for this server
30
+ # e.g. my_app_name
31
+ prefix: myapp
32
+
33
+ # AWS region your bucket lives in.
34
+ # (I suspect you only need to specify this when your 'location' is in a different region.)
35
+ region: ap-southeast-2
36
+
37
+ # Optional. Defaults to /var/www
38
+ file_location: '/var/www/html'
39
+ # The time zone that you'd like backups to be kept in.
40
+ # Backup files will be named with a timestamp located in the given timezone.
41
+ time_zone: 'Sydney'
42
+ # Optional. Will attempt to determine from operating system
43
+ # defaults to the value of the `time_zone` property above.
44
+ system_time_zone: 'UTC'
45
+
9
46
  logging:
10
47
  # DEBUG, INFO, WARN, ERROR, FATAL
11
- log_threshold: 'DEBUG'
48
+ log_threshold: 'WARN'
12
49
  # If set to true, logs to STDOUT and all the subsequent settings in this
13
50
  # section will be ignored.
14
- use_stdout: true
51
+ use_stdout: ffalse
15
52
  logfile_path: '/tmp/server_backup.log'
16
53
  keep_files: 1
17
54
  file_size:
18
55
  kilobytes: 100
19
56
 
20
- # Optional. Defaults to /var/www
21
- file_location: 'spec/fixtures/www'
22
- # The time zone that you'd like backups to be kept in.
23
- # Backup files will be named with a timestamp located in the given timezone.
24
- time_zone: 'Singapore'
25
- # Optional. Will attempt to determine from operating system
26
- # defaults to the value of the `time_zone` property above.
27
- system_time_zone: 'Asia/Ho_Chi_Minh'
28
-
29
57
  slack:
30
58
  # Set up a new webhook at https://slack.com/apps/A0F7XDUAZ-incoming-webhooks
31
59
  # Once configured, put the address here.
@@ -43,41 +71,12 @@ slack:
43
71
  - U9ASDFASD
44
72
 
45
73
  retention:
74
+ # How many hourly incremental backups to keep
46
75
  incremental:
47
- hours: 144
76
+ hours: 48
48
77
  daily:
49
78
  days: 6
50
79
  weekly:
51
80
  weeks: 3
52
81
  monthly:
53
82
  months: 11
54
-
55
- mysql:
56
- host: 127.0.0.1
57
- # Database to back up
58
- database:
59
- # MySql credentials
60
- user: root
61
- password:
62
- # Path (with trailing slash) to mysql commands e.g. mysqldump
63
- bin_path: /usr/local/bin/
64
- # If you are using MySql binary logging:
65
- # Path to the binary logs, should match the log_bin option in your my.cnf.
66
- # Comment out if you are not using mysql binary logging
67
- bin_log: /var/tmp/mysql-bin
68
-
69
- s3:
70
- # S3 credentials
71
- access_key_id: ASDFASDFASDFASDFASDF
72
- secret_access_key: asdfasdfasdfasdfasdfasdfasdfasdfasdfasdf
73
- # Bucket in which to store your backups
74
- # # Bucket in which to store your backups
75
- bucket: myapp-backup-test
76
-
77
- # The prefix under which to store and retrieve backups for this server
78
- # e.g. my_app_name
79
- prefix: my_test_app
80
-
81
- # AWS region your bucket lives in.
82
- # (I suspect you only need to specify this when your 'location' is in a different region.)
83
- region: ap-southeast-1
@@ -2,10 +2,23 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'fileutils'
5
-
6
- lib_dir = File.join(File.dirname(__FILE__), '..', 'lib')
5
+ require 'open3'
6
+ this_executable = File.expand_path(__FILE__)
7
+ this_dir = File.expand_path('..', File.dirname(__FILE__))
8
+ lib_dir = File.join(this_dir, 'lib')
7
9
  $LOAD_PATH.unshift lib_dir if File.directory?(lib_dir)
8
10
 
11
+ CRONTAB = <<-EOF
12
+ # Once per month:
13
+ 3 0 1 * * #{this_executable} monthly
14
+ # Once per week:
15
+ 5 0 * * 0 #{this_executable} weekly
16
+ # Once per day:
17
+ 5 0 * * 1-6 #{this_executable} daily
18
+ # And incremental backups once per hour
19
+ 5 1-23 * * * #{this_executable} incremental
20
+ EOF
21
+
9
22
  require 'server_backups'
10
23
  require 'main'
11
24
  require 'tmpdir'
@@ -133,6 +146,39 @@ Main do
133
146
  'files_only').values)
134
147
  end
135
148
  end
149
+ mode 'crontab' do
150
+ params[:backup_type].ignore!
151
+ def run
152
+ this_executable = File.expand_path(__FILE__)
153
+ current_crontab, stderr, status = Open3.capture3('crontab -l')
154
+ if current_crontab =~ Regexp.new(this_executable)
155
+ puts "Backups appear to be scheduled already."
156
+ puts "Run crontab -e to modify the schedule, or crontab -l to show it or crontab -r to delete it."
157
+ else
158
+ CRONTAB.split("\n").each do |line|
159
+ `(crontab -l 2>/dev/null; echo "#{line}") | crontab -`
160
+ end
161
+ puts "Backups are scheduled."
162
+ puts "Run crontab -e to modify the schedule, or crontab -l to show it or crontab -r to delete it."
163
+ end
164
+ end
165
+ end
166
+
167
+ mode 'create_config' do
168
+ params[:backup_type].ignore!
169
+ def run
170
+ this_dir = File.expand_path('..', File.dirname(__FILE__))
171
+ conf_file = File.join(this_dir, 'backup_conf.sample.yml')
172
+ new_file = File.expand_path("~/.backup_conf.yml")
173
+ if File.exists?(new_file)
174
+ puts "#{new_file} already exists. Please remove it before creating a new one."
175
+ else
176
+ FileUtils.copy(conf_file, new_file)
177
+ puts "I've added a backup configuration file at #{new_file}."
178
+ puts "Please edit it and make sure that your settings are correct."
179
+ end
180
+ end
181
+ end
136
182
 
137
183
  mode 'zones' do
138
184
  params[:backup_type].ignore!
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ServerBackups
4
- VERSION = '0.1.21'
4
+ VERSION = '0.1.22'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rtbackup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.21
4
+ version: 0.1.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Gannon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-25 00:00:00.000000000 Z
11
+ date: 2018-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -156,6 +156,7 @@ files:
156
156
  - LICENSE.txt
157
157
  - README.md
158
158
  - Rakefile
159
+ - advanced-configuration.md
159
160
  - backup_conf.sample.yml
160
161
  - bin/rtbackup
161
162
  - crontab.txt