Created
August 28, 2012 07:35
-
-
Save jverdeyen/3495884 to your computer and use it in GitHub Desktop.
Linux: Easy Peasy Backups
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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