Last active
February 22, 2024 06:32
-
-
Save labocho/af6b00cebde5ff6d27782f42d5214eb2 to your computer and use it in GitHub Desktop.
backup_config.rb
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
#!/usr/bin/env ruby | |
require "fileutils" | |
# rubocop:disable Style/MixinUsage | |
include FileUtils | |
# rubocop:enable Style/MixinUsage | |
CONFIG_FILES = %w( | |
config/database.yml | |
config/mail.yml | |
).freeze | |
DIR = "tmp/backup_config" | |
mkdir_p DIR | |
Dir.chdir("#{__dir__}/../../") do | |
case ARGV.first | |
when "backup" | |
CONFIG_FILES.each do |path| | |
bak = "#{DIR}/#{path}" | |
raise "#{bak} exists" if File.exist?(bak) | |
puts "cp #{path} #{bak}" | |
mkdir_p File.dirname(bak) | |
cp path, bak | |
end | |
when "restore" | |
CONFIG_FILES.each do |path| | |
bak = "#{DIR}/#{path}" | |
raise "#{bak} not exists" unless File.exist?(bak) | |
puts "cp #{bak} #{path}" | |
cp bak, path | |
end | |
rm_rf ".bundle/config" | |
else | |
warn "Usage: #{$0} (backup|restore)" | |
exit 1 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment