psql_backups 1.0.0 → 1.0.1
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.
- checksums.yaml +4 -4
- data/lib/psql_backups/version.rb +1 -1
- data/lib/tasks/psql_backups.rake +21 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71de16ab1c76bc340318cd1401cd525e248a5e5c
|
4
|
+
data.tar.gz: 76be553efe6d182f74188433fde426c035afe4e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bafb2129c8313bbbc52d4aae384603d9603e474713e9bf549ae2bf1e2105f028d4970954c9ca603272ea9871f4f54e6f74a349ffa2cbeec31b84773e57d03f8a
|
7
|
+
data.tar.gz: a81c54b01779a870cf671fc7136a0319ebbd18ed2f3c116175ac3217658a3804d212fdbb3ce0927bdb1c65508e6df88e839da4bf021de83684f0365a9b91a297
|
data/lib/psql_backups/version.rb
CHANGED
data/lib/tasks/psql_backups.rake
CHANGED
@@ -67,13 +67,32 @@ namespace :psql_backups do
|
|
67
67
|
|
68
68
|
puts "Your existing database will be replaced. Are you sure you want to continue? [y/N]"
|
69
69
|
input = STDIN.gets.chomp
|
70
|
-
raise
|
70
|
+
raise "User abort" unless input.downcase == "y"
|
71
71
|
|
72
72
|
restore_dbname = "#{ dbname }_#{ args[:tag] }"
|
73
|
-
backup_dbname = "#{ dbname }
|
73
|
+
backup_dbname = "#{ dbname }_auto_#{ Time.current.strftime("%Y%m%d%H%M%S") }"
|
74
74
|
ActiveRecord::Base.connection.disconnect!
|
75
75
|
`psql -c "alter database #{ dbname } rename to #{ backup_dbname };"`
|
76
76
|
`psql -c "create database #{ dbname } template #{ restore_dbname };"`
|
77
77
|
end
|
78
|
+
|
79
|
+
desc "Clear auto backups"
|
80
|
+
task clear: :environment do
|
81
|
+
raise "Can only be run in development environment" unless Rails.env.development?
|
82
|
+
raise "Can only be run if configured for local database" unless ActiveRecord::Base.connection.raw_connection.conninfo_hash[:host].nil?
|
83
|
+
|
84
|
+
puts "All your auto-backups will be cleared. Are you sure you want to continue? [y/N]"
|
85
|
+
input = STDIN.gets.chomp
|
86
|
+
raise "User abort" unless input.downcase == "y"
|
87
|
+
|
88
|
+
dbname = ActiveRecord::Base.connection.raw_connection.conninfo_hash[:dbname]
|
89
|
+
lines = `psql -c "\\l" | grep #{ dbname }_auto_`.split("\n")
|
90
|
+
backups = lines.map{|l| l.split('|').first.strip}
|
91
|
+
|
92
|
+
ActiveRecord::Base.connection.disconnect!
|
93
|
+
backups.each do |backup_dbname|
|
94
|
+
`psql -c "drop database #{backup_dbname};"`
|
95
|
+
end
|
96
|
+
end
|
78
97
|
end
|
79
98
|
|