Skip to content

Instantly share code, notes, and snippets.

@labocho
Last active February 22, 2024 06:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save labocho/af6b00cebde5ff6d27782f42d5214eb2 to your computer and use it in GitHub Desktop.
Save labocho/af6b00cebde5ff6d27782f42d5214eb2 to your computer and use it in GitHub Desktop.
backup_config.rb
#!/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