Skip to content

Instantly share code, notes, and snippets.

@jverdeyen
Created August 28, 2012 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jverdeyen/3495884 to your computer and use it in GitHub Desktop.
Save jverdeyen/3495884 to your computer and use it in GitHub Desktop.
Linux: Easy Peasy Backups
#!/bin/bash
new=$(date +%Y-%m-%d)
remove_old=$(date -d '7 days ago' +'%Y-%m-%d')
backup_dir="/media/ftp/backups/"
temp_dir="/tmp/"
source="/home/backups/*"
new_backup_dir="$backup_dir$new"
echo "Create new daily backup dir $new_backup_dir"
mkdir -p "$new_backup_dir"
for dir in $source
do
echo "Backing up -> $dir"
base=$(basename "$dir")
archive="$temp_dir$base.tar.gz"
echo "Creating archive $archive from $dir"
tar -zcf "$archive" $dir
echo "Copy $archive -> $new_backup_dir"
cp "$archive" "$new_backup_dir"
echo "Remove temp file $archive"
rm -f "$archive"
done
echo "Cleaning up old backup $backup_dir$remove_old"
rm -f "$backup_dir$remove_old
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment