backy_rb 0.1.4 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/backy/cli.rb +1 -1
- data/lib/backy/pg_restore.rb +18 -18
- data/lib/backy/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5869c45131402a06e9bd79a71e3cc82a3a0e867006fa9fa9b9f46bb7f1bd60b8
|
4
|
+
data.tar.gz: 614e88a654a7fd62d4426f8bbe1966ac3727229dbfe3d38dd5b171ae76e0bd9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c731f5764a173ba08cae49dc3abf6b4212b4b9b5f66757849b88b9be49511c13cd92fe8d64fb65e468992108b32ac877e1c2049afb5d390d8529f29092e746c4
|
7
|
+
data.tar.gz: 6e068f09ffaecbe95b9857cd947584a86ba3c0b18b70698cb709b91aa0711706de950121d47dbd03af91d0d3e610d790c2317296e742fcdf7e56456721f76abe
|
data/lib/backy/cli.rb
CHANGED
@@ -20,7 +20,7 @@ module Backy
|
|
20
20
|
file_name = Backy::PgDump.new.call
|
21
21
|
save_to_s3(file_name)
|
22
22
|
File.delete(file_name) if File.exist?(file_name)
|
23
|
-
Logger.
|
23
|
+
Logger.success("Dump pushed to S3 and local file deleted.")
|
24
24
|
end
|
25
25
|
|
26
26
|
desc "upload", "Upload a specific file to S3"
|
data/lib/backy/pg_restore.rb
CHANGED
@@ -15,11 +15,11 @@ module Backy
|
|
15
15
|
use_multicore = ENV["BACKY_USE_PARALLEL"] == "true"
|
16
16
|
|
17
17
|
if pigz_installed && multicore && use_multicore
|
18
|
-
|
18
|
+
Logger.log('Using parallel restore with pigz')
|
19
19
|
parallel_restore
|
20
20
|
else
|
21
|
-
|
22
|
-
|
21
|
+
Logger.log("Pigz not installed or system is not multicore")
|
22
|
+
Logger.log('Using plain text restore')
|
23
23
|
plain_text_restore
|
24
24
|
end
|
25
25
|
end
|
@@ -31,11 +31,11 @@ module Backy
|
|
31
31
|
def plain_text_restore
|
32
32
|
cmd = "(#{pg_password_env}psql -c \"#{terminate_connection_sql};\" #{pg_credentials} #{database}; #{pg_password_env}dropdb #{pg_credentials} #{database}; #{pg_password_env}createdb #{pg_credentials} #{database}; gunzip -c #{file_name} | #{pg_password_env}psql #{pg_credentials} -q -d #{database}) 2>&1 >> #{log_file}"
|
33
33
|
|
34
|
-
|
34
|
+
Logger.log("Restoring #{database} from #{file_name} ...")
|
35
35
|
if system(cmd)
|
36
|
-
|
36
|
+
Logger.log("Database restoration completed successfully.")
|
37
37
|
else
|
38
|
-
|
38
|
+
Logger.log("Database restoration failed. See #{log_file} for details.")
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -50,40 +50,40 @@ module Backy
|
|
50
50
|
# Terminate connections and drop/create database
|
51
51
|
terminate_and_recreate_db = "(#{pg_password_env}psql -c \"#{terminate_connection_sql};\" #{pg_credentials} #{database}; #{pg_password_env}dropdb #{pg_credentials} #{database}; #{pg_password_env}createdb #{pg_credentials} #{database}) 2>&1 >> #{log_file}"
|
52
52
|
|
53
|
-
|
53
|
+
Logger.log("Terminating connections to #{database}")
|
54
54
|
if system(terminate_and_recreate_db)
|
55
|
-
|
55
|
+
Logger.log("Database connections terminated and database recreated.")
|
56
56
|
else
|
57
|
-
|
57
|
+
Logger.log("Error during database termination and recreation. See #{log_file}")
|
58
58
|
return
|
59
59
|
end
|
60
60
|
|
61
61
|
# Decompress and restore
|
62
|
-
|
62
|
+
Logger.log("Decompressing #{file_name} into #{dump_dir} ...")
|
63
63
|
if system(decompress_cmd)
|
64
|
-
|
64
|
+
Logger.log("Decompression completed successfully.")
|
65
65
|
|
66
66
|
# Check the expected file
|
67
67
|
unless File.exist?("#{dump_dir}/toc.dat")
|
68
|
-
|
68
|
+
Logger.log("toc.dat not found in #{dump_dir}.")
|
69
69
|
return
|
70
70
|
end
|
71
71
|
else
|
72
|
-
|
72
|
+
Logger.log("Decompression failed. See #{log_file} for details.")
|
73
73
|
return
|
74
74
|
end
|
75
75
|
|
76
|
-
|
76
|
+
Logger.log("Restoring database from #{dump_dir} ...")
|
77
77
|
if system(restore_cmd)
|
78
|
-
|
78
|
+
Logger.log("Database restoration completed successfully.")
|
79
79
|
else
|
80
|
-
|
80
|
+
Logger.log("Database restoration failed. See #{log_file} for details.")
|
81
81
|
return
|
82
82
|
end
|
83
83
|
|
84
|
-
|
84
|
+
Logger.log("Cleanup: Removing #{dump_dir} ...")
|
85
85
|
FileUtils.rm_rf(dump_dir)
|
86
|
-
|
86
|
+
Logger.log("Cleanup completed.")
|
87
87
|
end
|
88
88
|
|
89
89
|
def terminate_connection_sql
|
data/lib/backy/version.rb
CHANGED