You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
931 B
Bash
40 lines
931 B
Bash
#!/bin/bash
|
|
|
|
# This runs in a cronjob every hour
|
|
# e.g. 0 */1 * * * /home/nathan/scripts/backup/backup_mc.sh -s mc -d /srv/mc -b /home/nathan/backups/mcRdiff/mc -r nathan@alphavps.aney.co.uk -R ~/backups/minecraft/mc
|
|
|
|
while getopts s:d:b:r:R:n: flag
|
|
do
|
|
case "${flag}" in
|
|
s) SERVERNAME=${OPTARG};;
|
|
d) DIR=${OPTARG};;
|
|
b) BACKUPDIR=${OPTARG};;
|
|
r) REMOTE=${OPTARG};;
|
|
R) REMOTEBACKUP=${OPTARG};;
|
|
n) NOW=${OPTARG};;
|
|
esac
|
|
done
|
|
|
|
TIME=$(date +%H%M)
|
|
|
|
# Make backup location if it's not there
|
|
mkdir -p $BACKUPDIR
|
|
|
|
# Rdiff to reduce the storage needs of rsync
|
|
rdiff-backup \
|
|
--exclude $DIR/scripts/ \
|
|
$DIR $BACKUPDIR
|
|
|
|
# If time is 00:00/midnight
|
|
if [ "$TIME" = 0000 ] || [ "$NOW" = 1 ]
|
|
then
|
|
# Create the remote directory for backup if it doesn't exist
|
|
ssh $REMOTE mkdir -p $REMOTEBACKUP
|
|
# Copy the backup accross
|
|
# -e ssh makes it secure
|
|
rsync -azh -e ssh \
|
|
$BACKUPDIR/ \
|
|
$REMOTE:$REMOTEBACKUP
|
|
fi
|
|
|