Tuesday, January 21, 2025
HomeRuby On RailsKamal Database Backups | Drifting Ruby

Kamal Database Backups | Drifting Ruby


# Terminal
kamal console
kamal accent boot postgres_backup
kamal accent restart postgres_backup # will not copy new setting variables
kamal accent reboot postgres_backup
kamal accent logs postgres_backup
# .kamal/secrets and techniques
POSTGRES_PASSWORD=$(bin/rails runner "places Rails.utility.credentials.dig(:postgres, :password)")
POSTGRES_PASS=$(bin/rails runner "places Rails.utility.credentials.dig(:postgres, :password)")
# .irbrc
def rails_environment
  Rails.env
finish

if outlined?(Rails)
  def colorize(textual content, color_code) = "e[#{color_code}m#{text}e[0m"
  def red(text) = colorize(text, 31)
  def green(text) = colorize(text, 32)
  def blue(text) = colorize(text, 36)

  prompt = case rails_environment
  when "development"
             green(rails_environment)
  when "production"
             "e[1;41;97m!!PRODUCTION!!e[0m #{red(rails_environment)}"
  else
             blue(rails_environment)
  end

  IRB.conf[:PROMPT][:RAILS] = {
    PROMPT_I: "#{immediate}>",
    PROMPT_N: "#{immediate}>",
    PROMPT_S: "#{immediate}*",
    PROMPT_C: "#{immediate}?",
    RETURN: " => %sn"
  }

  IRB.conf[:PROMPT_MODE] = :RAILS
finish
# config/deploy.yml
aliases:
  console: app exec --interactive --reuse "bin/rails console --sandbox"
  shell: app exec --interactive --reuse "bash"
  logs: app logs -f
  dbc: app exec --interactive --reuse "bin/rails dbconsole"

equipment:
  postgres_backup:
    picture: kartoza/pg-backup:17-3.5
    host: 192.168.1.217
    env:
      clear:
        POSTGRES_USER: instance
        POSTGRES_DB: example_production
        POSTGRES_HOST: 192.168.1.217
        POSTGRES_PORT: 5432
        CRON_SCHEDULE: "*/10 * * * *"
      secret:
        - POSTGRES_PASS
    directories:
      - backups:/backups
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments