Last active
April 28, 2016 11:35
-
-
Save fuzzylogiq/f767a287ae62815ba6ac to your computer and use it in GitHub Desktop.
Simple backup script for deploystudio running from external drive
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/sh | |
echo "backup_home_dirs.sh - v1.0 - ("`date`")" | |
set -e | |
TMPFILE="/tmp/Backup-${DS_SERIAL_NUMBER}-`date "+%Y%m%d"`.dmg" | |
DS_INTERNAL_DRIVE=`system_profiler SPSerialATADataType|awk -F': ' '/Mount Point/ {print $2}'|head -n1` | |
MOUNTPOINT="/Volumes/UserBackups-${DS_SERIAL_NUMBER}" | |
SPARSE="${TMPFILE}.sparseimage" | |
SOURCE="${DS_INTERNAL_DRIVE}/Users/" | |
if [ ! -d "${SOURCE}" ]; then | |
echo "No Users folder to backup!" | |
exit 0 | |
fi | |
echo "Cleaning up from previous runs..." | |
if [ -e "${SPARSE}" ]; then | |
rm -f "${SPARSE}" | |
fi | |
find /Volumes -type d -name "UserBackup*" -maxdepth 1 -print0 | while read -d $'\0' DIR | |
do | |
hdiutil detach "$DIR" | |
done | |
echo "Checking if enough space..." | |
USERS_SIZE=`du -sm "${SOURCE}" | awk '{print $1}'` | |
echo "User folder is ${USERS_SIZE} MB" | |
FREE_SPACE=`df -m / | sed '1d' | awk '{print $4}'` | |
echo "Backup disk has ${FREE_SPACE} MB free" | |
if [[ ${USERS_SIZE} -gt $((FREE_SPACE-1000)) ]]; then | |
echo "Users folder is too large for backup disk, backup not possible." | |
exit 1 | |
fi | |
echo "Creating sparseimage..." | |
hdiutil create "${TMPFILE}" -type SPARSE -fs HFS+ -volname "UserBackups-${DS_SERIAL_NUMBER}" | |
echo "Attaching sparseimage..." | |
hdiutil attach -noautoopen -nobrowse -owners on "${SPARSE}" | |
echo "Copying ${SOURCE} to ${MOUNTPOINT}..." | |
# ditto -vV "${SOURCE}" "${MOUNTPOINT}" | |
rsync -arv --exclude="Library/Caches" \ | |
--exclude="Library/PubSub" \ | |
--exclude="Library/Fonts" \ | |
--exclude="support/" \ | |
--exclude="ics/" \ | |
--exclude="Shared/" \ | |
"${SOURCE}" "${MOUNTPOINT}" | |
# diff -qr "${SOURCE}" "${MOUNTPOINT}" | |
echo "Moving temp sparseimage to Backups folder..." | |
cp "${SPARSE}" /Backups/ | |
rm -f "${SPARSE}" | |
echo "Detaching image..." | |
hdiutil detach "${MOUNTPOINT}" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment