Allow $RSYNC_TEST_TMP to indicate a good tmp dir for our tests.
[rsync/rsync.git] / testsuite / backup.test
CommitLineData
7d059d4c
WD
1#! /bin/sh
2
3# Copyright (C) 2004 by Wayne Davison <wayned@samba.org>
4
5# This program is distributable under the terms of the GNU GPL (see
6# COPYING).
7
8# Test that the --backup option works right.
9
10. "$suitedir/rsync.fns"
11
4d8f5b0a 12bakdir="$tmpdir/bak"
7d059d4c 13
21cddef2 14makepath "$fromdir/deep" "$bakdir/dname"
f1271537
WD
15name1="$fromdir/deep/name1"
16name2="$fromdir/deep/name2"
7d059d4c 17
4d8f5b0a 18outfile="$scratchdir/rsync.out"
7d059d4c 19
fc9d64c9
WD
20cat "$srcdir"/[gr]*.[ch] > "$name1"
21cat "$srcdir"/[et]*.[ch] > "$name2"
7d059d4c 22
21cddef2 23checkit "$RSYNC -ai --info=backup '$fromdir/' '$todir/'" "$fromdir" "$todir"
7d059d4c 24
21cddef2 25checkit "$RSYNC -ai --info=backup '$fromdir/' '$chkdir/'" "$fromdir" "$chkdir"
fc9d64c9
WD
26cat "$srcdir"/[fgpr]*.[ch] > "$name1"
27cat "$srcdir"/[etw]*.[ch] > "$name2"
7d059d4c 28
21cddef2 29$RSYNC -ai --info=backup --no-whole-file --backup "$fromdir/" "$todir/" \
4d8f5b0a 30 | tee "$outfile"
f1271537 31for fn in deep/name1 deep/name2; do
4d8f5b0a 32 grep "backed up $fn to $fn~" "$outfile" >/dev/null || test_fail "no backup message output for $fn"
f1271537 33 diff $diffopt "$fromdir/$fn" "$todir/$fn" || test_fail "copy of $fn failed"
4d8f5b0a
WD
34 diff $diffopt "$chkdir/$fn" "$todir/$fn~" || test_fail "backup of $fn to $fn~ failed"
35 mv "$todir/$fn~" "$todir/$fn"
36done
7d059d4c 37
cd36049c 38echo deleted-file >"$todir/dname"
844810d6 39cp_touch "$todir/dname" "$chkdir"
cd36049c 40
21cddef2 41checkit "$RSYNC -ai --info=backup --no-whole-file --delete-delay \
7918f244 42 --backup --backup-dir='$bakdir' '$fromdir/' '$todir/'" "$fromdir" "$todir" \
4d8f5b0a 43 | tee "$outfile"
7d059d4c 44
f1271537 45for fn in deep/name1 deep/name2; do
4d8f5b0a
WD
46 grep "backed up $fn to .*/$fn$" "$outfile" >/dev/null || test_fail "no backup message output for $fn"
47done
48diff -r $diffopt "$chkdir" "$bakdir" || test_fail "backup dir contents are bogus"
cd36049c 49rm "$bakdir/dname"
7d059d4c 50
21cddef2 51checkit "$RSYNC -ai --info=backup --del '$fromdir/' '$chkdir/'" "$fromdir" "$chkdir"
fc9d64c9
WD
52cat "$srcdir"/[efgr]*.[ch] > "$name1"
53cat "$srcdir"/[ew]*.[ch] > "$name2"
4d8f5b0a 54
21cddef2 55checkit "$RSYNC -ai --info=backup --inplace --no-whole-file --backup --backup-dir='$bakdir' '$fromdir/' '$todir/'" "$fromdir" "$todir" \
4d8f5b0a
WD
56 | tee "$outfile"
57
f1271537 58for fn in deep/name1 deep/name2; do
4d8f5b0a
WD
59 grep "backed up $fn to .*/$fn$" "$outfile" >/dev/null || test_fail "no backup message output for $fn"
60done
61diff -r $diffopt "$chkdir" "$bakdir" || test_fail "backup dir contents are bogus"
62
21cddef2 63checkit "$RSYNC -ai --info=backup --inplace --no-whole-file '$fromdir/' '$bakdir/'" "$fromdir" "$bakdir"
7d059d4c
WD
64
65# The script would have aborted on error, so getting here means we've won.
66exit 0