Add backup commands
This commit is contained in:
Executable
+15
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This script will automatically be invoked by the backup system from the target directory. Use whatever bash commands
|
||||
# you like to backup any files needed into the current directory. The following will grab everything from your home
|
||||
# directory which commonly includes data you may care about. If there are other things you want to save, be sure to
|
||||
# add them in.
|
||||
|
||||
rsync -az --delete /Users/andrew/ ./Users/andrew \
|
||||
--exclude .DS_Store \
|
||||
--exclude .Trash \
|
||||
--exclude .dropbox \
|
||||
--exclude Dropbox \
|
||||
--exclude Library \
|
||||
--include Library/Application\ Support
|
||||
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
|
||||
BACKUP_COMMANDS="$HOME/.backup-commands.sh"
|
||||
BIN_DIR=$(dirname $0)
|
||||
|
||||
read -p "Enter your backup drive host: " HOST
|
||||
read -p "Enter your backup drive share: " SHARE
|
||||
read -p "Enter your backup drive username: " USERNAME
|
||||
read -p "Enter your backup drive password: " -s PASSWORD
|
||||
|
||||
MASKED_PASSWORD=$(echo $PASSWORD | sed "s/./*/g")
|
||||
|
||||
echo; read -p "Backup to afp://$USERNAME:$MASKED_PASSWORD@$HOST/$SHARE? (Y/n): " CONFIRM
|
||||
[[ "$CONFIRM" == "" ]] && CONFIRM="Y"
|
||||
CONFIRM=$(echo $CONFIRM | tr "a-z" "A-Z")
|
||||
if [[ "$CONFIRM" != "Y" ]]; then
|
||||
echo "Aborting backup init."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
security add-generic-password -a $USER -s backup-host -w "$HOST"
|
||||
security add-generic-password -a $USER -s backup-share -w "$SHARE"
|
||||
security add-generic-password -a $USER -s backup-username -w "$USERNAME"
|
||||
security add-generic-password -a $USER -s backup-password -w "$PASSWORD"
|
||||
|
||||
cp $BIN_DIR/backup-commands.default.sh "$BACKUP_COMMANDS"
|
||||
chmod u+x "$BACKUP_COMMANDS"
|
||||
|
||||
echo; echo ">>>> PLEASE READ THIS! <<<<"
|
||||
echo "The file '.backup-commands.sh' has been created in your home directory."
|
||||
echo "Please review it to be sure it covers everything you want to back up."
|
||||
read -p "(press enter to continue)"
|
||||
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
|
||||
function die {
|
||||
echo $*; exit 1
|
||||
}
|
||||
LOCAL_MOUNT="$HOME/.backup-drive"
|
||||
|
||||
HOST=$(security find-generic-password -a $USER -s backup-host -w)
|
||||
SHARE=$(security find-generic-password -a $USER -s backup-share -w)
|
||||
USERNAME=$(security find-generic-password -a $USER -s backup-username -w)
|
||||
PASSWORD=$(security find-generic-password -a $USER -s backup-password -w)
|
||||
DRIVE="afp://$USERNAME:$PASSWORD@$HOST/$SHARE"
|
||||
|
||||
if ! mount | grep -q "$HOME/$LOCAL_MOUNT"; then
|
||||
if [[ -e "$LOCAL_MOUNT" ]]; then
|
||||
rm -rf "$LOCAL_MOUNT" || die "Could not mount to $LOCAL_MOUNT"
|
||||
fi
|
||||
mkdir -p "$LOCAL_MOUNT"
|
||||
mount -t afp "$DRIVE" "$LOCAL_MOUNT" || die "Could not mount from $DRIVE"
|
||||
fi
|
||||
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
|
||||
function die {
|
||||
echo $*; exit 1
|
||||
}
|
||||
|
||||
LOCAL_MOUNT="$HOME/.backup-drive"
|
||||
BACKUP_COMMANDS="$HOME/.backup-commands.sh"
|
||||
STARTED_DATE=$(date)
|
||||
|
||||
[[ -x "$BACKUP_COMMANDS" ]] || die "Could not find $BACKUP_COMMANDS"
|
||||
|
||||
echo "Starting backup at $STARTED_DATE..."
|
||||
|
||||
./backup-unmount.sh || die
|
||||
./backup-mount.sh || die
|
||||
[[ -d "$LOCAL_MOUNT" ]] || die "Could find $LOCAL_MOUNT"
|
||||
|
||||
(
|
||||
cd "$LOCAL_MOUNT"
|
||||
echo "Started backing up at $STARTED_DATE" > backup.log
|
||||
"$BACKUP_COMMANDS" >> backup.log 2>&1
|
||||
)
|
||||
|
||||
if [[ "$?" != 0 ]]; then
|
||||
echo "ERROR: Backup failed!"
|
||||
head -n10 "$LOCAL_MOUNT/backup.log"
|
||||
echo "..."
|
||||
tail -n10 "$LOCAL_MOUNT/backup.log"
|
||||
fi
|
||||
|
||||
./backup-unmount.sh || echo "WARNING: Could not unmount $LOCAL_MOUNT! Please check into this!"
|
||||
echo "Finished backing up at $(date)."
|
||||
|
||||
Executable
+12
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
function die {
|
||||
echo $*; exit 1
|
||||
}
|
||||
LOCAL_MOUNT="$HOME/.backup-drive"
|
||||
|
||||
if mount | grep -q "$LOCAL_MOUNT"; then
|
||||
umount "$LOCAL_MOUNT" || die "Could not unmount $LOCAL_MOUNT"
|
||||
fi
|
||||
[[ -e "$LOCAL_MOUNT" ]] && rm -r "$LOCAL_MOUNT"
|
||||
|
||||
Reference in New Issue
Block a user