Skip to content

Instantly share code, notes, and snippets.

@codeniko
Last active August 29, 2015 14:01
Show Gist options
  • Save codeniko/685998117c81dfe7c0a9 to your computer and use it in GitHub Desktop.
Save codeniko/685998117c81dfe7c0a9 to your computer and use it in GitHub Desktop.
Shell script to backup home directory and /usr/local/bin to a FAT32 device (daily cron)
#!/bin/sh
mnt=/mnt/codeniko
mntWindows=/mnt/windows
dev=/dev/sdb1
devWindows=/dev/sda1 # OPTIONAL for useful files on windows partition
log=/var/log/codeniko_backup
excl=/home/niko/.rsync_backup_exclude.lst
incl=/home/niko/.rsync_backup_include.lst
if [ ! -d "${mnt}" ]; then
/bin/mkdir "${mnt}"
fi
if ! /bin/mountpoint -q "${mnt}"; then
/bin/mount -t 'vfat' "${dev}" "${mnt}"
if [ $? -ne 0 ]; then
/bin/echo "`/bin/date` - Unable to mount ${dev} to ${mnt}" >> "${log}"
exit 1
fi
fi
/usr/bin/rsync -rtqDz --modify-window=1 --delete --include-from="${incl}" --exclude-from="${excl}" '/home/niko/' "${mnt}/home/"
/usr/bin/rsync -rtqDz --modify-window=1 --delete '/usr/local/bin/' "${mnt}/localbin/"
# OPTIONAL - for useful files on windows partition
if ! /bin/mountpoint -q "${mntWindows}"; then
/bin/mount -t 'ntfs' "${devWindows}" "${mntWindows}"
if [ $? -ne 0 ]; then
/bin/echo "`/bin/date` - Unable to mount ${devWindows} to ${mntWindows}" >> "${log}"
/bin/umount "${mnt}"
exit 1
fi
fi
/usr/bin/rsync -rtqDz --modify-window=1 --delete "${mntWindows}/Documents and Settings/Niko/Desktop/Coding/" "${mnt}/windows/Desktop/Coding"
/usr/bin/rsync -rtqDz --modify-window=1 --delete "${mntWindows}/Documents and Settings/Niko/Documents/Visual Studio 2010/Projects" "${mnt}/windows/VS2010"
# END OF OPTIONAL - for Windows
/bin/umount "${mnt}"
/bin/umount "${mntWindows}" # OPTIONAL - for Windows
exit 0
Downloads
Pictures
Music
.*
.*/
.bash_logout
.bashrc
.fonts
.fontconfig
.git*
.mozilla
.rsync_backup*
.tmux.conf
.vim*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment