-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmcfly.sh
executable file
·135 lines (114 loc) · 3.95 KB
/
mcfly.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
# mcfly - an rsync based, snapshot backups script
#
# Author: Diego Escalante Urrelo <diegoe@gnome.org>
# URL: http://github.com/diegoe/mcfly
#
# Arguments: ./mcfly dir-to-backup destination-drive
#
# Inspired by
# http://blog.interlinked.org/tutorials/rsync_time_machine.html
# http://blog.interlinked.org/tutorials/rsync_addendum.yaml.html
# Uncomment for lots of debugging
# set -x
# Configurable vars
mcfly_dir_name="mcfly"
# OSX Note: the system's rsync sucks. Get the one from homebrew-dupes.
rsync=/usr/local/bin/rsync
from=$1
to=$2
date=`date "+%Y-%m-%dT%H_%M_%S"`
host=`hostname -s`
# What to backup
drive_source=$from
dir_source=`basename $from`
exclude_file=$drive_source/.rsync-exclude
# Where and how to name it
path_dest=$to/$mcfly_dir_name
dir_dest=$dir_source-$date
tmp_dest=$path_dest/incomplete-$dir_dest
permanent_dest=$path_dest/$dir_dest
# This path is relative to $dir_dest
current_link=$dir_source-current
link_dest=../$current_link
# Don't touch anything if the dir exists
if [ -d $permanent_dest ]; then
exit;
fi
# Check that there's a current symlink
if [ ! -h $path_dest/$current_link ]; then
exit;
fi
# OSX note: some applications install files to ~/Library or similar.
# This sucks, because it forces us to pass --no-g (ignore group
# preservation) or run rsync as sudo. Both things suck.
#
# But --no-g should be more acceptable than sudo.
# OSX note: -X does not work with OSX's rsync.
# If you still insist on using it paleolithic rsync, replace -X with
# --extended-attributes.
#
# WARNING: ResourceForks in HFS+ behave stupidily with old rsync.
# OSX note: ResourceForks is something Apple invented to piss everyone.
# If you encounter files that keep being copied to your backups you can
# check if they have the com.apple.ResourceFork xattr with:
# $ xattr file
# or
# $ ls -l@ file
#
# If you find such an abomination, you can remove it with:
# $ xattr -d com.apple.ResourceFork file
#
# WARNING: I have no clue if this attribute holds important information
# on certain filetypes. For me, it has not been a problem. Be careful.
# Linux note: when copying to a different FS, xattrs might not be
# preserved, and will make rsync "fail", preventing the later steps from
# happening.
#
# Remove the -X option to avoid this. This should be safe, unless you
# explicitely need xattr of some file.
# Linux note: rsync can copy symlinks that point to other filesystems,
# even if they are broken. This is a problem later when hard linking.
# The solution is to use --copy-links or --safe-links.
# Other useful options:
# --extended-attributes \
# --dry-run \
# A reference of the codes printed by --itemize
# http://pagesofinterest.net/blog/2010/11/rsync-itemize-output-codes/
# A suggested list of excludes for OSX is inlined.
# IT DOES NOT WORK! OMG!
# That is because I intentionally leave the -n (dry-run) switch when
# committing to the repository. This is for everyone's safety.
#
# Just remove the line and mcfly will be execute your instructions.
#--exclude="Library/Google" \
#--exclude="Library/Caches" \
#--exclude="Music/" \
$rsync \
-rpto \
-n \
--modify-window=5 \
--verbose --itemize-changes \
--human-readable \
--delete \
--links \
--safe-links \
--exclude="Documents/Final Cut Pro Documents/Render Files/" \
--exclude="Documents/Final Cut Pro Documents/Waveform Cache Files/" \
--exclude="Documents/Final Cut Pro Documents/Thumbnail Cache Files/" \
--exclude="Documents/Final Cut Pro Documents/Audio Render Files/" \
--exclude="Library/Caches/" \
--exclude="Library/Preferences/Macromedia/" \
--exclude=".cache/" \
--exclude=".Trash/" \
--exclude="Downloads/" \
--exclude="Dropbox/" \
--log-file=$tmp_dest.log \
--link-dest=$link_dest \
$drive_source $tmp_dest
# Move to final destination, if this fails then nothing else gets
# executed.
mv $tmp_dest $permanent_dest \
&& mv $tmp_dest.log $permanent_dest.log \
&& rm -f $path_dest/$current_link \
&& ln -s $dir_dest $path_dest/$current_link