Skip to content

Commit

Permalink
add mongodb backup (#1746)
Browse files Browse the repository at this point in the history
  • Loading branch information
li9ht authored Dec 21, 2021
1 parent 6877ead commit d8819dd
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions scripts/homestead.rb
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,10 @@ def self.configure(config, settings)
if enabled_databases.include? 'postgresql'
Homestead.backup_postgres(database, "#{dir_prefix}/postgres_backup", config)
end
# Backup MongoDB
if enabled_databases.include? 'mongodb'
Homestead.backup_mongodb(database, "#{dir_prefix}/mongodb_backup", config)
end
end
end

Expand Down Expand Up @@ -694,4 +698,12 @@ def self.backup_postgres(database, dir, config)
trigger.run_remote = {inline: "mkdir -p #{dir}/#{now} && echo localhost:5432:#{database}:homestead:secret > ~/.pgpass && chmod 600 ~/.pgpass && pg_dump -U homestead -h localhost #{database} > #{dir}/#{now}/#{database}-#{now}.sql"}
end
end

def self.backup_mongodb(database, dir, config)
now = Time.now.strftime("%Y%m%d%H%M")
config.trigger.before :destroy do |trigger|
trigger.warn = "Backing up mongodb database #{database}..."
trigger.run_remote = {inline: "mkdir -p #{dir}/#{now} && mongodump --db #{database} --out #{dir}/#{now}"}
end
end
end

0 comments on commit d8819dd

Please sign in to comment.