-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed tests, updated databasse dependency
- Loading branch information
Showing
6 changed files
with
109 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,28 @@ | ||
s3_asset_backup CHANGELOG | ||
========================= | ||
# s3_asset_backup CHANGELOG | ||
|
||
|
||
This file is used to list changes made in each version of the s3_asset_backup cookbook. | ||
|
||
0.1.0 | ||
0.3.0 | ||
----- | ||
- [your_name] - Initial release of s3_asset_backup | ||
- Fixed tests, updated databasse dependency | ||
|
||
0.2.0 | ||
0.2.4 | ||
----- | ||
- Significant mods to the configuration of asstes to be backed up. | ||
- Added option to backup multiple databases using a name prefix ending in '*' | ||
- Changed default backup prefix to '%Y-%m-%d' (e.g. "2015-11-04") because it makes more sense. | ||
|
||
0.2.1 | ||
0.2.3 | ||
----- | ||
- Removed use_inline_resources from provider base class because it somehow prevents the generation of actual base-defined resources when the node is built. | ||
- Fixed syslog logging. Replaced the success_message resource attribute with a good fixed message, and rewrote the mysql script to work ok when there are duplicated databases and tables. | ||
|
||
0.2.2 | ||
----- | ||
- Fixed greivous error where the config.yml file was written with % as wildcard but the script file expected *. | ||
|
||
0.2.3 | ||
----- | ||
- Fixed syslog logging. Replaced the success_message resource attribute with a good fixed message, and rewrote the mysql script to work ok when there are duplicated databases and tables. | ||
|
||
0.2.4 | ||
----- | ||
- Changed default backup prefix to '%Y-%m-%d' (e.g. "2015-11-04") because it makes more sense. | ||
## 0.2.0 | ||
- Significant mods to the configuration of asstes to be backed up. | ||
- Added option to backup multiple databases using a name prefix ending in '*' | ||
|
||
- - - | ||
Check the [Markdown Syntax Guide](http://daringfireball.net/projects/markdown/syntax) for help with Markdown. | ||
## 0.1.0 | ||
- [your_name] - Initial release of s3_asset_backup | ||
|
||
The [Github Flavored Markdown page](http://github.github.com/github-flavored-markdown/) describes the differences between markdown on github and standard markdown. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require 'aws-sdk' | ||
require 'open3' | ||
require 'syslog' | ||
require 'yaml' | ||
|
||
TEMP_TGZ_FILE = 'temp/tgz' | ||
|
||
def run_system_command(command) | ||
stdout, stderr, exit_status = Open3.capture3(command) | ||
unless exit_status.success? | ||
puts [stdout, stderr].join("\n") | ||
raise "Command failed: #{command}" | ||
end | ||
stdout | ||
end | ||
|
||
mysql_user, mysql_pw, restore_prefix = ARGV | ||
unless mysql_user && mysql_pw | ||
puts "Restore selected selected sql dump file from S3 storage." | ||
puts "usage: ruby #{__FILE__} mysql_user mysql_password <restore_prefix, default = current backup prefix>" | ||
exit | ||
end | ||
restore_prefix ||= Time.now.strftime(s3['time_prefix']) | ||
|
||
config = YAML.load_file('config.yml') | ||
s3 = config['s3'] | ||
objects_saved = 0 | ||
s3_client = Aws::S3::Client.new(access_key_id: s3['access_key_id'], secret_access_key: s3['secret_access_key'], region: s3['region']) | ||
selected_backup_files = Aws::S3::Bucket.new(s3['bucket'], client: s3_client).objects(prefix: restore_prefix) | ||
|
||
puts "Ready to restore #{selected_backup_files.size} sql files from bucket #{s3['bucket']} with prefix '#{restore_prefix}'." | ||
puts "[Enter] to start." | ||
gets | ||
|
||
selected_backup_files.each do |backup_file| | ||
tarfile = backup_file.key.split('/').last | ||
sqlfile = tarfile.split('.tgz').first | ||
dbname = sqlfile.split('.sql').first | ||
backup_file.get({response_target: tarfile}) | ||
run_system_command "tar -xvzf " + tarfile | ||
run_system_command "mysql -u #{mysql_user} -p#{mysql_password} -e 'drop database if exists `#{dbname}`'" | ||
run_system_command "mysql -u #{mysql_user} -p#{mysql_password} -e 'create database `#{dbname}`'" | ||
run_system_command "cat sqlfile | mysql --database=#{dbname}" | ||
puts "Loaded #{sqlfile} (#{File.new(sqlfile).size} bytes) to database '#{dbname}'" | ||
File.delete tarfile | ||
File.delete sqlfile | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ARGV.each do|a| | ||
puts "Argument: #{a}" | ||
end | ||
puts "zero: #{ARGV[0]}" | ||
puts "zero is null?: #{ARGV[0].nil?}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters