server_backups 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0acb87133c33b34ff515fff6e6186f91ac5717a8
4
+ data.tar.gz: 1d4086a756cdf6310058763f9ca159698321dfa0
5
+ SHA512:
6
+ metadata.gz: d4e18e316446d6b8e9ee132f1b723130993e9d05cc9f862b5fa86c16f7c621ba15d985f47632c1d3cb955054cd91896140a7091ed60c3a0dde169b5b42416dfa
7
+ data.tar.gz: aff7a18c7cb285f6d55fc9d1a50e9dea83524667943ea301c8cbd645b23a546de3fced372cdff33f6b7732ff5c7ab0771235b8507f6417b9b4c2433547ad1c78
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ *.gem
13
+ .vscode/settings.json
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,15 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ # inherit_from: .rubocop_todo.yml
4
+
5
+ Layout/IndentationWidth:
6
+ Width: 4
7
+
8
+ Metrics/LineLength:
9
+ Max: 100
10
+
11
+ Metrics/MethodLength:
12
+ Max: 20
13
+
14
+ Style/Documentation:
15
+ Enabled: false
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,35 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2018-03-30 15:34:28 +0700 using RuboCop version 0.54.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 5
10
+ # Configuration parameters: CountComments, ExcludedMethods.
11
+ Metrics/BlockLength:
12
+ Max: 69
13
+
14
+ # Offense count: 1
15
+ # Configuration parameters: CountComments.
16
+ Metrics/ClassLength:
17
+ Max: 110
18
+
19
+ # Offense count: 1
20
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
21
+ # URISchemes: http, https
22
+ Metrics/LineLength:
23
+ Max: 102
24
+
25
+ # Offense count: 1
26
+ # Configuration parameters: CountKeywordArgs.
27
+ Metrics/ParameterLists:
28
+ Max: 6
29
+
30
+ # Offense count: 1
31
+ # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
32
+ # AllowedNames: io, id, to
33
+ Naming/UncommunicativeMethodParamName:
34
+ Exclude:
35
+ - 'bin/server_backup'
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.1
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.0
5
+ before_install: gem install bundler -v 1.16.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at tgannon@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in server_backups.gemspec
8
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,89 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ server_backups (0.1.8)
5
+ activesupport (~> 5.1)
6
+ aws-sdk-s3 (~> 1.8)
7
+ main (~> 6.2)
8
+ slack-notifier (~> 2.3)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ activesupport (5.1.5)
14
+ concurrent-ruby (~> 1.0, >= 1.0.2)
15
+ i18n (~> 0.7)
16
+ minitest (~> 5.1)
17
+ tzinfo (~> 1.1)
18
+ addressable (2.5.2)
19
+ public_suffix (>= 2.0.2, < 4.0)
20
+ arrayfields (4.9.2)
21
+ aws-partitions (1.73.0)
22
+ aws-sdk-core (3.17.1)
23
+ aws-partitions (~> 1.0)
24
+ aws-sigv4 (~> 1.0)
25
+ jmespath (~> 1.0)
26
+ aws-sdk-kms (1.5.0)
27
+ aws-sdk-core (~> 3)
28
+ aws-sigv4 (~> 1.0)
29
+ aws-sdk-s3 (1.8.2)
30
+ aws-sdk-core (~> 3)
31
+ aws-sdk-kms (~> 1)
32
+ aws-sigv4 (~> 1.0)
33
+ aws-sigv4 (1.0.2)
34
+ chronic (0.10.2)
35
+ concurrent-ruby (1.0.5)
36
+ crack (0.4.3)
37
+ safe_yaml (~> 1.0.0)
38
+ diff-lcs (1.3)
39
+ fattr (2.4.0)
40
+ hashdiff (0.3.7)
41
+ i18n (0.9.5)
42
+ concurrent-ruby (~> 1.0)
43
+ jmespath (1.3.1)
44
+ main (6.2.2)
45
+ arrayfields (~> 4.7, >= 4.7.4)
46
+ chronic (~> 0.6, >= 0.6.2)
47
+ fattr (~> 2.2, >= 2.2.0)
48
+ map (~> 6.1, >= 6.1.0)
49
+ map (6.6.0)
50
+ minitest (5.11.3)
51
+ public_suffix (3.0.2)
52
+ rake (10.5.0)
53
+ rspec (3.7.0)
54
+ rspec-core (~> 3.7.0)
55
+ rspec-expectations (~> 3.7.0)
56
+ rspec-mocks (~> 3.7.0)
57
+ rspec-core (3.7.1)
58
+ rspec-support (~> 3.7.0)
59
+ rspec-expectations (3.7.0)
60
+ diff-lcs (>= 1.2.0, < 2.0)
61
+ rspec-support (~> 3.7.0)
62
+ rspec-mocks (3.7.0)
63
+ diff-lcs (>= 1.2.0, < 2.0)
64
+ rspec-support (~> 3.7.0)
65
+ rspec-support (3.7.1)
66
+ safe_yaml (1.0.4)
67
+ slack-notifier (2.3.2)
68
+ thread_safe (0.3.6)
69
+ tzinfo (1.2.5)
70
+ thread_safe (~> 0.1)
71
+ vcr (4.0.0)
72
+ webmock (3.3.0)
73
+ addressable (>= 2.3.6)
74
+ crack (>= 0.3.2)
75
+ hashdiff
76
+
77
+ PLATFORMS
78
+ ruby
79
+
80
+ DEPENDENCIES
81
+ bundler (~> 1.16)
82
+ rake (~> 10.5)
83
+ rspec (~> 3.0)
84
+ server_backups!
85
+ vcr (~> 4.0)
86
+ webmock (~> 3.3)
87
+
88
+ BUNDLED WITH
89
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Tyler Gannon
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,167 @@
1
+ # Backup Website and Mysql databases to S3
2
+
3
+ Automated backup and recovery solution capable of restoring files and databases
4
+ to a given point in time.
5
+
6
+ * Incremental backups of files using [GNU Tar](https://www.gnu.org/software/tar/)
7
+ * Incremental backups of databases using binary logging
8
+ * Files are stored in a structured manner within an Amazon S3 bucket using
9
+ [AWS S3 SDK gem](https://github.com/aws/aws-sdk-ruby)
10
+
11
+ **Key assumptions made:**
12
+
13
+ * All databases except system databases will be backed up.
14
+ * Mysql database only.
15
+ * Mysql binary logging is turned on.
16
+ * The **GNU** (not BSD) version of _tar_. The GNU version includes --listed-incremental, which is needed for incremental backups.
17
+
18
+ ## Installation
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.
23
+
24
+ ### Ubuntu
25
+
26
+ ```bash
27
+
28
+ sudo apt install ruby ruby-dev zlib1g-dev
29
+ sudo gem install server_backups-0.x.x.gem
30
+
31
+ ```
32
+
33
+ ### Configure Mysql Bin Logging
34
+
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
+ ```
37
+ [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
+
42
+ ```
43
+
44
+ Then restart mysql:
45
+
46
+ ```
47
+ sudo service mysql restart
48
+ ```
49
+
50
+ ### Grant user read access to mysql binary logs and also to your web root
51
+
52
+ ```bash
53
+ # Make sure you know what the group ownership is, for your web root.
54
+ sudo usermod -a -G www-data ubuntu
55
+ sudo usermod -a -G mysql ubuntu
56
+ ```
57
+
58
+ ###
59
+
60
+ ## Usage
61
+
62
+ ### Set up a configuration file
63
+
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.
67
+
68
+ ### Set up your crontab.
69
+
70
+ * Use `crontab -e` to edit cron configuration.
71
+
72
+ **Sample Crontab configuration**
73
+
74
+ ```
75
+
76
+ # Once per month:
77
+ 3 0 1 * * /usr/local/bin/server_backup monthly
78
+ # Once per week:
79
+ 5 0 * * 0 /usr/local/bin/server_backup weekly
80
+ # Once per day:
81
+ 5 0 * * 1-6 /usr/local/bin/server_backup daily
82
+ # And incremental backups once per hour
83
+ 5 1-23 * * * /usr/local/bin/server_backup incremental
84
+
85
+ ```
86
+
87
+ ### Command line parameters
88
+
89
+ #### 1) For taking backups:
90
+
91
+ some examples
92
+
93
+ ```bash
94
+ # Take a full backup and store it in the monthly backups location.
95
+ server_backup monthly
96
+
97
+ # Take a full backup as normal, but instead of backing up all databases,
98
+ # only back up `mydatabase`.
99
+ server_backup daily -d mydatabase
100
+
101
+ server_backup daily -f # only back up the files, not the database(s)
102
+ server_backup daily -b # only back up the database(s), not the files
103
+
104
+ # Take an incremental backup, but load the given configuration file.
105
+ server_backup incremental -c /etc/my_backup_configuration.cnf
106
+
107
+ ```
108
+
109
+ #### 2) List (or search) time zones for help with configuration
110
+
111
+ ```bash
112
+ server_backup zones # list all
113
+ server_backup zones america # case insensitive search for zones containing a string
114
+ ```
115
+
116
+ #### 3) Restore backups
117
+
118
+ ```bash
119
+ # Restore up to the latest backup data available on s3
120
+ server_backlup restore
121
+
122
+ # Restore up to two days ago at 3pm in the configured
123
+ # time zone (see config file).
124
+ server_backup restore --up_to='two days ago at 3:00 PM'
125
+
126
+ # To make it easier to decide what time your restore point
127
+ # should be, you can write the restore point time in any time
128
+ # zone and it will be translated to the server's normal time zone.
129
+ #
130
+ # This way, if the server is in UTC and you're in Singapore, you
131
+ # don't necessarily have to do any confusing time maths in order
132
+ # to restore back to what time it was before you made a mistake
133
+ # and updated a wordpress plugin. ;)
134
+ server_backup restore --up_to='March 28 12:00 PM' --time_zone='Singapore'
135
+
136
+ ```
137
+
138
+ ```
139
+ NAME
140
+ server_backup
141
+
142
+ SYNOPSIS
143
+ server_backup (restore|zones) backup_type [options]+
144
+
145
+ PARAMETERS
146
+ backup_type (1 -> symbol(backup_type))
147
+ specifies the backup type to perform [incremental | daily | weekly |
148
+ monthly]
149
+ --config=config, -c (0 ~> config=~/.backup_conf.yml)
150
+ load configuration from YAML file
151
+ --database=database, -d (default ~> database=all)
152
+ Which database to back up, defaults to all non-system databases.
153
+ --db_only, -b (default ~> false)
154
+ If specified
155
+ --files_only=[files_only], -f (de ~> files_only)
156
+ Only work with files.
157
+ --help, -h
158
+ ```
159
+
160
+ ### Restore your application
161
+
162
+ ```bash
163
+ website_backup restore app_name
164
+ ```
165
+
166
+
167
+ * Everything in /var/www
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,82 @@
1
+ ###############################################################################
2
+ #
3
+ # Sample Backup Configuration
4
+ #
5
+ #
6
+ #
7
+ ###############################################################################
8
+
9
+ logging:
10
+ # DEBUG, INFO, WARN, ERROR, FATAL
11
+ log_threshold: 'DEBUG'
12
+ # If set to true, logs to STDOUT and all the subsequent settings in this
13
+ # section will be ignored.
14
+ use_stdout: true
15
+ logfile_path: '/tmp/server_backup.log'
16
+ keep_files: 1
17
+ file_size:
18
+ kilobytes: 100
19
+
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
+ slack:
30
+ # Set up a new webhook at https://slack.com/apps/A0F7XDUAZ-incoming-webhooks
31
+ # Once configured, put the address here.
32
+ webhook: https://hooks.slack.com/services/asdasdasdasdasdasdasdasdasdasd
33
+ # If you want to babysit your backups, set this true.
34
+ notify_on_success: true
35
+ # A list of user ids of persons to @mention when posting success messages.
36
+ mention_users_on_failure:
37
+ - U9ASDFASD
38
+ # - U8SXDFG34
39
+ # - U23SDU3LD
40
+ # - U3234ASD4
41
+ # Leave empty for none.
42
+ mention_users_on_success:
43
+ - U9ASDFASD
44
+
45
+ retention:
46
+ incremental:
47
+ hours: 144
48
+ daily:
49
+ days: 6
50
+ weekly:
51
+ weeks: 3
52
+ monthly:
53
+ months: 11
54
+
55
+ mysql:
56
+ # Database to back up
57
+ database:
58
+ # MySql credentials
59
+ user: root
60
+ password:
61
+ # Path (with trailing slash) to mysql commands e.g. mysqldump
62
+ bin_path: /usr/local/bin/
63
+ # If you are using MySql binary logging:
64
+ # Path to the binary logs, should match the log_bin option in your my.cnf.
65
+ # Comment out if you are not using mysql binary logging
66
+ bin_log: /var/tmp/mysql-bin
67
+
68
+ s3:
69
+ # S3 credentials
70
+ access_key_id: ASDFASDFASDFASDFASDF
71
+ secret_access_key: asdfasdfasdfasdfasdfasdfasdfasdfasdfasdf
72
+ # Bucket in which to store your backups
73
+ # # Bucket in which to store your backups
74
+ bucket: myapp-backup-test
75
+
76
+ # The prefix under which to store and retrieve backups for this server
77
+ # e.g. my_app_name
78
+ prefix: my_test_app
79
+
80
+ # AWS region your bucket lives in.
81
+ # (I suspect you only need to specify this when your 'location' is in a different region.)
82
+ region: ap-southeast-1
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'server_backups'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)