Backup directories

says all you need to backup is « public/uploads ». i’m guessing it is not any more. « .gitignore » includes several directories, such as « invoices », and « proof_of_identity_files ».

if my guess is correct, that means a release might add new directories that you should backup. am I correct?

Your guess is correct! :wink:

I would say you have to backup every volumes listed in the docker-compose file, excepted public/packs (which are generated), log (unless you want it) and plugin (unless you have some plugins).

just hacked up a script to backup files. should work on any platforms.

#!/usr/bin/env ruby

require "yaml"
require "open3"
require "shellwords"
require "date"
require "pathname"

fab_root_dir = Pathname.new(ARGV.first || Dir.pwd)

docker_compose_file = fab_root_dir / "setup" / "docker-compose.yml"
config = YAML.load(File.read(docker_compose_file))

target_directories = config["services"]["fabmanager"]["volumes"].map { |s| s.split(":").first.gsub(/\${PWD}\//, "") }

# do not backup generated files
target_directories.reject! { |s| s == "public/packs" }

timestamp = DateTime.now.iso8601
backup_dir = fab_root_dir / "backup"
backup_filename = backup_dir / format("backup-%s.tgz", timestamp)
backup_command = format("tar -cvzf %s -C %s %s",
                          backup_filename.to_s.shellescape,
                          fab_root_dir.to_s.shellescape,
                          target_directories.map { |d| d.shellescape }.join(" ")
                       )

Dir.mkdir(backup_dir.to_s) unless Dir.exists?(backup_dir.to_s)
target_directories.each do |d|
  full_path = fab_root_dir / d
  Dir.mkdir(full_path.to_s) unless Dir.exists?(full_path.to_s)
end

stdout, stderr, status = Open3.capture3(backup_command)
puts "STDOUT"
puts stdout
puts "STDERR"
puts stderr
puts format("Exit status: %d", status.to_i)
exit status.to_i
1 « J'aime »