Created
July 11, 2010 22:02
-
-
Save wolever/471886 to your computer and use it in GitHub Desktop.
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 | |
set -e | |
if [[ `whoami` != "root" ]] | |
then | |
echo "Gotta be root..." | |
exit $? | |
fi | |
function cleanup() { | |
[[ "$DID_CLEANUP" == "yes" ]] && return; | |
echo "Unmounting secure backup..." | |
cd / | |
umount /mnt/backup | |
cryptsetup luksClose backup | |
DID_CLEANUP="yes" | |
} | |
trap cleanup EXIT | |
echo "Mounting secure backup..." | |
cryptsetup luksOpen --key-file ~/.backupKey /dev/sda3 backup | |
mount /dev/mapper/backup /mnt/backup | |
echo "Backup starting..." | |
cd /mnt/backup | |
mysqldump --all-databases -u root --password='my SQL--' > /root/mysql_dump.sql | |
LOUD="--progress --stats -vi" | |
rsync --delete -al --human-readable --verbose --stats --progress --ignore-errors --exclude "/proc/" --exclude "/mnt/" --exclude "/sys/" --exclude "/dev/" --exclude "/tmp/" / /mnt/backup/ | |
cleanup | |
echo "Backup done :)" |
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 | |
# Make sure you've got the correct version of rsync (ie, the one that correctly | |
# copies Mac extended filesystem stuff). | |
# Mine (which I think is correct) is: | |
# $ /opt/local/bin/rsync --version | |
# rsync version 3.0.5 protocol version 30 | |
# Copyright (C) 1996-2008 by Andrew Tridgell, Wayne Davison, and others. | |
# Web site: http://rsync.samba.org/ | |
# Capabilities: | |
# 64-bit files, 32-bit inums, 32-bit timestamps, 64-bit long ints, | |
# socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace, | |
# append, ACLs, xattrs, iconv, symtimes, file-flags | |
set -e | |
SRC="/" | |
if [[ "$1" == "--home" ]] | |
then | |
SRC="/Users/"; | |
shift | |
fi | |
DST="/Volumes/MacBookBackup$SRC" | |
echo "Backing up from $SRC to $DST" | |
sleep 3 || exit 2 | |
if [[ `whoami` != 'root' ]] | |
then | |
echo "Gotta be root." | |
exit 2 | |
fi | |
if [[ ! -d "$DST" ]] | |
then | |
echo "$DST does not exist." | |
exit 42 | |
fi | |
cat > /tmp/rsync_exclude <<"EOF" | |
/dev/ | |
/Network/ | |
/cores/ | |
/afs/ | |
/automount/ | |
/private/tmp/ | |
/private/var/vm/ | |
/Previous Systems.localized | |
.Spotlight-*/ | |
Library/Caches/ | |
EOF | |
NICE="nice -n 20" | |
ARGS="$ARGS --acls --xattrs --one-file-system --hard-links --archive --sparse " | |
ARGS="$ARGS --crtimes --human-readable --fileflags --force-change --progress " | |
ARGS="$ARGS --stats --ignore-errors --delete --delete-excluded" | |
$NICE /opt/local/bin/rsync $ARGS --exclude-from=/tmp/rsync_exclude "$SRC" "$DST" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment