Skip to content

Instantly share code, notes, and snippets.

@5c0tt
Created September 16, 2015 11:29
Show Gist options
  • Select an option

  • Save 5c0tt/5feb84d9485131c958de to your computer and use it in GitHub Desktop.

Select an option

Save 5c0tt/5feb84d9485131c958de to your computer and use it in GitHub Desktop.
Rotating Folder Backup Script
#!/bin/bash
# Taken from http://triq.net/script/rotating-folder-backup-script
# because the site is slow and down, and I wanted to review this later
# Originally created by zany on Tue, 03/17/2009 - 13:38
BASEDIR=/home/projects # SET THIS
BAKDIR=/home/backups # SET THIS
stamp=$(date +%Y-%m-%d)
cd "$BASEDIR"
for prj in * ; do
find "$prj" -mtime -1 -type f | grep "" >/dev/null && {
tar cjf "$BAKDIR/${prj}_${stamp}.tar.bz2" "$prj"
find "$BAKDIR" -name "${prj}_*" -mtime -14 -mtime +7 -not -name "*-01.*" -exec rm {} \;
ls -sh "$BAKDIR/${prj}_"*
}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment