Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
41 lines (33 sloc)
912 Bytes
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 | |
# | |
# | |
# BACKUP Script | |
# | |
# | |
# backup.sh <remote host> <remote path> <local path> | |
# | |
# | |
REMOTE_HOST=$1 | |
REMOTE_PATH=$2 | |
LOCAL_PATH=$3 | |
if [ ! -d $LOCAL_PATH ]; then | |
echo "Local path $LOCAL_PATH does not exist" | |
exit | |
fi | |
# | |
BACKUP_DATE=$(date +%F-%T) | |
LAST_BACKUP=$(ls -t $LOCAL_PATH | head -1) | |
LAST_BACKUP_PATH="$LOCAL_PATH/$LAST_BACKUP" | |
NEW_BACKUP_PATH="$LOCAL_PATH/$BACKUP_DATE" | |
if [ ! -d $LAST_BACKUP_PATH ]; then | |
echo "Local last backup is invalid" | |
exit | |
fi | |
logger -t backup "backup $NEW_BACKUP_PATH start" | |
echo "Backup $REMOTE_HOST:$REMOTE_PATH on $BACKUP_DATE to $LOCAL_PATH ($NEW_BACKUP_PATH)" | |
echo " - rsync $LAST_BACKUP_PATH / $NEW_BACKUP_PATH" | |
rsync -av --exclude-from=/backup/backup.exclude --numeric-ids --link-dest=$LAST_BACKUP_PATH $REMOTE_HOST:$REMOTE_PATH $NEW_BACKUP_PATH | |
if [ -d $NEW_BACKUP_PATH ]; then | |
touch $NEW_BACKUP_PATH | |
fi | |
logger -t backup "backup $NEW_BACKUP_PATH stop" | |