Skip to content

Instantly share code, notes, and snippets.

@dcnl1980
Last active November 29, 2016 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcnl1980/1f6badb4b06573f2ed6df86cb3d6d533 to your computer and use it in GitHub Desktop.
Save dcnl1980/1f6badb4b06573f2ed6df86cb3d6d533 to your computer and use it in GitHub Desktop.
Linux backup script
#/bin/sh
# This file is under construction and will be update regulary, so it can be a cron-shell for backing up Linux based systems.
# put this in the cronjob to run the backup every day at 2:15
# 15 2 * * * /var/backups/backup.sh
current="$(date +'%d_%m_%Y_%H_%M_%S')"
# MYSQL BACKUP
sudo mysqldump -u root -pPASSWORD --all-databases | gzip > /var/backups/dbbackup_$current.sql.gz
# WEBSITES BACKUP
sudo tar czf /var/backups/sitebackup_$current.tar -C / var/www && gzip /var/backups/sitebackup_$current.tar
# DELETE OLD BACKUPS > 7 days
find /var/backups/db* -mtime +7 -exec rm {} \;
find /var/backups/site* -mtime +7 -exec rm {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment