Skip to content

Instantly share code, notes, and snippets.

@jeongho
Last active March 8, 2017 22:56
Show Gist options
  • Save jeongho/a414afd678bfd50af439 to your computer and use it in GitHub Desktop.
Save jeongho/a414afd678bfd50af439 to your computer and use it in GitHub Desktop.
mysql backup cron job
#!/usr/bin/env bash
#
# Schedule in cron as local time 11:00PM local time (e.g. PST '00 07 * * * bash /home/antarctica/backup_cloudera_db.sh)
user=root
password=root_password
database=scm
archive_days=7
# Backing Up MySQL Databases
sudo bash -c 'mysqldump -hlocalhost -u$user -p$password $database | gzip -9 > /data01/backup/cm_scm_db.$(date +%Y%m%d).sql.gz'
# Backing Up PostgreSQL Databases
#PGPASSWORD=$password pg_dump -h localhost -p 7432 -U $database | gzip -9 > /data01/backup/pgsql_scm_server_db_backup.$(date +%Y%m%d).sql.gz
sudo find -name *.gz -type f -mtime +$archive_days -exec rm -f {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment