Created
May 14, 2010 22:08
-
-
Save graysky/401739 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Probably a better way, but couldn't find one to make a mysql database dump | |
# that includes the schema of all tables, but excludes the contents of certain tables (like sessions, delayed_jobs) | |
# that just bloat the size of the backup. | |
# | |
def mysql_db_backup | |
raw_dump = Tempfile.new("raw_db_dump") | |
dump_file = Tempfile.new("dump") | |
# First dump just the full schema | |
cmd = "mysqldump --quick --single-transaction --no-data --create-options #{mysql_options} > #{raw_dump.path}" | |
run(cmd) | |
# Then the content excluding unneeded tables: sessions and delayed_jobs | |
db = db_credentials[:database] | |
cmd = "mysqldump --quick --single-transaction --ignore-table=#{db}.sessions --ignore-table=#{db}.delayed_jobs --create-options #{mysql_options} >> #{raw_dump.path}" | |
run(cmd) | |
# Now gzip compress | |
cmd = "gzip -c #{raw_dump.path} > #{dump_file.path}" | |
run(cmd) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment