Skip to content

Instantly share code, notes, and snippets.

@zaiddabaeen
Created January 12, 2016 11:28
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 zaiddabaeen/44036f06dd5df55b22dc to your computer and use it in GitHub Desktop.
Save zaiddabaeen/44036f06dd5df55b22dc to your computer and use it in GitHub Desktop.
Automate the backup of your projects locally and remove old backups.
#!/bin/bash
# Automate the backup of your projects locally and remove old backups.
# Run a daily cronjob such as:
# 0 1 * * * bash /etc/cron.daily/code_backup.sh >/dev/null 2>&1
# Author: Zaid Daba'een
projects=( project1 project2 project3 )
for i in "${projects[@]}"
do
tar -zcf /var/backup/$i-`date +\%Y\%m\%d`.tar.gz /var/www/sites/$i
done
find /var/backup/ -type f -mtime +2 -exec rm -f {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment