summaryrefslogtreecommitdiff
path: root/ansible/roles/holywood2/files/rsync-to-nalanda
blob: 20f3cfe4253506a0d7a16ade2fadab2d9c966bb4 (plain)
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
#!/bin/bash

set -euo pipefail

from="$1"
server="$2"
dir="$3"
shift 3

new="$dir/new"
dated="$dir/$(date -Id)"

echo "Syncing $from to staging area on $server"
rsync -rlthHS --partial --stats --exclude=lost+found \
	"$from/." "$server:$new/." "$@"
echo

if ssh "$server" test -e "$dated"; then
	echo "$dated exists, removing it"
	ssh "$server" find "$dated" -type d -exec chmod +rw '{}' +
	ssh "$server" rm -rf "$dated"
fi

echo "Making a hardlink copy to $dated"
ssh "$server" mkdir "$dated"
ssh "$server" cp -al "$new/." "$dated/."

echo
ssh "$server" df -h .
echo

echo "All good"
echo