Compress database backups.

Fixes bug 951600.

The update_gerrit_users.py script creates a database backup
everytime it runs. This change compresses the backups as they
are being made and adds a cron job that will remove backups that
are 30 days or older. Current backups will need to be manually
compressed.

Change-Id: Idb90d4af629892f1bc2e3e98f35f7de2ad58d4be
This commit is contained in:
David Shrewsbury 2012-05-03 09:27:14 -04:00
parent 39ff8df701
commit 2b7496c0ee
3 changed files with 11 additions and 2 deletions

View File

@ -83,7 +83,7 @@ DB_DB = gerrit_config.get("database","database")
db_backup_file = "%s.%s.sql" % (DB_DB, datetime.isoformat(datetime.now()))
db_backup_path = os.path.join(GERRIT_BACKUP_PATH, db_backup_file)
retval = os.system("mysqldump --opt -u%s -p%s %s > %s" %
retval = os.system("mysqldump --opt -u%s -p%s %s | gzip -9 > %s.gz" %
(DB_USER, DB_PASS, DB_DB, db_backup_path))
if retval != 0:
print "Problem taking a db dump, aborting db update"

View File

@ -79,7 +79,7 @@ DB_DB = gerrit_config.get("database","database")
def make_db_backup():
db_backup_file = "%s.%s.sql" % (DB_DB, datetime.isoformat(datetime.now()))
db_backup_path = os.path.join(GERRIT_BACKUP_PATH, db_backup_file)
retval = os.system("mysqldump --opt -u%s -p%s %s > %s" %
retval = os.system("mysqldump --opt -u%s -p%s %s | gzip -9 > %s.gz" %
(DB_USER, DB_PASS, DB_DB, db_backup_path))
if retval != 0:
logger.error("Problem taking a db dump, aborting db update")

View File

@ -140,6 +140,15 @@ class gerrit($virtual_hostname='',
command => 'find /home/gerrit2/review_site/git/ -type d -name "*.git" -print -exec git --git-dir="{}" repack -afd \;',
environment => "PATH=/usr/bin:/bin:/usr/sbin:/sbin",
}
cron { "removedbdumps":
user => gerrit2,
hour => 5,
minute => 1,
command => 'find /home/gerrit2/dbupdates/ -name "*.sql.gz" -mtime +30 -exec rm -f {} \;',
environment => "PATH=/usr/bin:/bin:/usr/sbin:/sbin",
}
} # testmode==false
file { "/var/log/gerrit":