summaryrefslogtreecommitdiffstats
path: root/test/backup-files.test
blob: 8cbfc1cbaaed3d97acb3b4fae41b8962b797369a (plain) (blame)
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
Unit test of the backup-files script.

	# Test backup without options; it should link, not copy
	$ echo foo > foo
	$ echo bar > "space bar"
	$ sleep 1
	$ %{QUILT_DIR}/scripts/backup-files -B backup/ -b foo
	> Copying foo

	$ ls -l foo | awk '{ print $2 }'
	> 2
	$ ls -l backup/foo | awk '{ print $2 }'
	> 2
	$ [ backup/foo -nt foo ] && echo "mtimes differ"

	$ %{QUILT_DIR}/scripts/backup-files -B backup/ -r foo
	> Restoring foo
	$ ls -l foo | awk '{ print $2 }'
	> 1

	# Test silent backup with -L; it should copy, not link
	$ %{QUILT_DIR}/scripts/backup-files -B backup/ -b -s -L foo

	$ ls -l foo | awk '{ print $2 }'
	> 1
	$ ls -l backup/foo | awk '{ print $2 }'
	> 1
	$ [ backup/foo -nt foo ] && echo "mtimes differ"

	# Test restore without options
	$ echo modified > foo
	$ sleep 1
	$ %{QUILT_DIR}/scripts/backup-files -B backup/ -r foo
	> Restoring foo

	$ cat foo
	> foo
	$ [ -e backup/foo ] && echo "backup/foo not deleted"
	$ [ -e backup ] && echo "backup directory not deleted"

	# Test backup files with hard links
	$ ln foo foo2
	$ %{QUILT_DIR}/scripts/backup-files -B backup/ -b -s -L foo
	$ ls -l foo | awk '{ print $2 }'
	> 1
	$ ls -l backup/foo | awk '{ print $2 }'
	> 2

	$ %{QUILT_DIR}/scripts/backup-files -B backup/ -b -s -L foo2
	$ ls -l foo | awk '{ print $2 }'
	> 1
	$ ls -l foo2 | awk '{ print $2 }'
	> 1
	$ ls -l backup/foo | awk '{ print $2 }'
	> 2
	$ ls -l backup/foo2 | awk '{ print $2 }'
	> 2

	# Test restore of files with hard links
	$ rm -f foo foo2
	$ %{QUILT_DIR}/scripts/backup-files -B backup/ -r -s foo
	$ ls -l foo | awk '{ print $2 }'
	> 2
	$ ls -l backup/foo2 | awk '{ print $2 }'
	> 2
	$ [ -e backup/foo ] && echo "backup/foo not deleted"
	$ [ ! -e foo2 ] || echo "file foo2 shouldn't exist"

	$ %{QUILT_DIR}/scripts/backup-files -B backup/ -r -s foo2
	$ ls -l foo | awk '{ print $2 }'
	> 2
	$ ls -l foo2 | awk '{ print $2 }'
	> 2
	$ [ -e backup/foo2 ] && echo "backup/foo2 not deleted"
	$ [ -e backup ] && echo "backup directory not deleted"

	# Test restore with -t
	$ %{QUILT_DIR}/scripts/backup-files -B backup/ -b -s foo
	$ touch -r foo foo.timeref
	$ %{QUILT_DIR}/scripts/backup-files -B backup/ -r -s -t foo

	$ ls -l foo | awk '{ print $2 }'
	> 2
	$ [ foo -nt foo.timeref ] || echo "touch failed"

	# Test restore with -k
	$ %{QUILT_DIR}/scripts/backup-files -B backup/ -b -s -L foo "space bar"
	$ touch -r "space bar" bar.timeref
	$ ls -l backup/foo | awk '{ print $2 }'
	> 2
	$ ls -l "backup/space bar" | awk '{ print $2 }'
	> 1
	$ mkdir tmp
	$ cd tmp
	$ %{QUILT_DIR}/scripts/backup-files -B ../backup/ -r -s -k foo "space bar"
	$ cd ..

	$ ls -l foo | awk '{ print $2 }'
	> 1
	$ ls -l "space bar" | awk '{ print $2 }'
	> 1
	$ ls -l backup/foo | awk '{ print $2 }'
	> 3
	$ ls -l "backup/space bar" | awk '{ print $2 }'
	> 2
	$ ls -l tmp/foo | awk '{ print $2 }'
	> 3
	$ ls -l "tmp/space bar" | awk '{ print $2 }'
	> 2
	$ rm -rf tmp

	# Test restore all (-)
	$ rm -f foo "space bar"
	$ %{QUILT_DIR}/scripts/backup-files -B backup/ -r -s -t -
	$ cat foo
	> foo
	$ cat "space bar"
	> bar
	$ [ "space bar" -nt bar.timeref ] || echo "touch failed"

	# Backup and restore a non-existing files
	$ mkdir "dir with spaces"
	$ %{QUILT_DIR}/scripts/backup-files -B backup/ -b -s -L new "dir with spaces/space file"
	$ echo data > new
	$ echo data2 > "dir with spaces/space file"
	$ ls -l backup/new | awk '{ print $5 }'
	> 0
	$ ls -l "backup/dir with spaces/space file" | awk '{ print $5 }'
	> 0
	$ %{QUILT_DIR}/scripts/backup-files -B backup/ -r -s -
	$ [ ! -e backup/new ] || echo "file backup/new shouldn't exist"
	$ [ ! -e new ] || echo "file new shouldn't exist"
	$ [ ! -e "backup/dir with spaces/space file" ] || echo "file backup/dir with spaces/space file shouldn't exist"
	$ [ ! -e "dir with spaces/space file" ] || echo "file dir with spaces/space file shouldn't exist"

	# Test restore involving a dir name with spaces
	$ echo data > "dir with spaces/space file"
	$ %{QUILT_DIR}/scripts/backup-files -B backup/ -b -L "dir with spaces/space file"
	> Copying dir with spaces/space file
	$ rm -rf "dir with spaces"
	$ %{QUILT_DIR}/scripts/backup-files -B backup/ -r -
	> Restoring dir with spaces/space file
	$ cat "dir with spaces/space file"
	> data
	$ [ -e backup ] && echo "backup directory not deleted"

	# Test backup reading file list from a file
	$ %{QUILT_DIR}/scripts/backup-files -B backup/ -b -s -L -f -
	< foo
	< new
	< space bar
	$ echo data > new
	$ echo modified > foo
	$ rm -f "space bar"
	$ [ -e backup/new -a ! -s backup/new ] || echo "file backup/new isn't empty"
	$ ls -l backup/new | awk '{ print $5 }'
	> 0
	$ cat backup/foo
	> foo
	$ cat "backup/space bar"
	> bar
	$ %{QUILT_DIR}/scripts/backup-files -B backup/ -r -s -f -
	< foo
	< new
	< space bar
	$ [ ! -e backup/new ] || echo "file backup/new shouldn't exist"
	$ [ ! -e new ] || echo "file new shouldn't exist"
	$ cat foo
	> foo
	$ cat "space bar"
	> bar

	# Test the special -L alone case
	$ %{QUILT_DIR}/scripts/backup-files -B backup/ -b -L -f -
	< new
	< foo
	< space bar
	> New file new
	> Copying foo
	> Copying space bar
	$ ln "space bar" "linked space"
	$ ls -l foo | awk '{ print $2 }'
	> 1
	$ ls -l "space bar" | awk '{ print $2 }'
	> 2
	$ %{QUILT_DIR}/scripts/backup-files -B backup/ -L -
	$ ls -l foo | awk '{ print $2 }'
	> 1
	$ ls -l "space bar" | awk '{ print $2 }'
	> 1
	$ [ ! -e new ] || echo "file new shouldn't exist"
	# Second call should be idempotent
	$ %{QUILT_DIR}/scripts/backup-files -B backup/ -L -
	$ ls -l foo | awk '{ print $2 }'
	> 1
	$ ls -l "space bar" | awk '{ print $2 }'
	> 1
	$ [ ! -e new ] || echo "file new shouldn't exist"
	$ %{QUILT_DIR}/scripts/backup-files -B backup/ -r - | sort
	> Removing new
	> Restoring foo
	> Restoring space bar
	$ rm "linked space"

	# Test copy (as used by quilt snapshot)
	$ %{QUILT_DIR}/scripts/backup-files -B snapshot/ -c -f -
	< new
	< foo
	< space bar
	< dir with spaces/space file
	> New file new
	> Copying foo
	> Copying space bar
	> Copying dir with spaces/space file
	$ ls -l foo | awk '{ print $2 }'
	> 2
	$ ls -l "space bar" | awk '{ print $2 }'
	> 1
	$ ls -l "dir with spaces/space file" | awk '{ print $2 }'
	> 1
	$ [ ! -e new ] || echo "file new shouldn't exist"
	$ ls -l snapshot/new | awk '{ print $2 }'
	> 1
	$ ls -l snapshot/foo | awk '{ print $2 }'
	> 1
	$ ls -l snapshot/"space bar" | awk '{ print $2 }'
	> 1
	$ ls -l snapshot/"dir with spaces/space file" | awk '{ print $2 }'
	> 1
	$ [ ! -s new ] || echo "file snapshot/new should be empty"
	$ rm -rf snapshot