summaryrefslogtreecommitdiffstats
path: root/roles/s3-mirror/files/s3sync
blob: f8d04137cac2eb9b404f97a4bd7ea6e8ff938415 (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
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
#!/bin/bash

logfile="/var/log/s3-mirror/s3sync.log"
tree="/srv/pub/"
s3cmd=/usr/bin/s3cmd
curdate=`date +%s`

if [ ! -d ${tree} ]; then
    echo "Specified root of the directory tree (${tree}) does not exist. Exiting." | tee ${logfile}
    exit 1
fi

exec 1>>${logfile} 2>&1

function newer()
{
    if [ "$1" -nt "$2" ] ; then
	return 0
    fi
    return 1
}

S3CMD_ARGS="sync \
  --verbose \
  --preserve \
  --recursive \
  --check-md5 \
  --delay-updates \
  --guess-mime-type --mime-type application/octet-stream \
  --reduced-redundancy \
  --acl-public \
  --exclude-from /usr/local/etc/s3-mirror-excludes.txt \
  "

content="epel"
targets="s3-mirror-us-east-1 s3-mirror-us-west-1 s3-mirror-us-west-2 s3-mirror-eu-west-1 s3-mirror-ap-northeast-1"
report=0

if [ -e /var/run/s3-mirror/lastrun ]; then
        . /var/run/s3-mirror/lastrun
else
        # 48 hours -> 172800 seconds
        let lastrun=curdate-172800
fi

let delta=curdate-lastrun

# hardcoded to epel only '-e'
/usr/local/bin/last-sync -d ${delta} -e

if [ "$?" -ne "0" ]; then
    # no changes since the last sync
    # abort
    exit 0
fi

for c in ${content}; do
    if $(newer ${tree}/${c}/fullfilelist /var/lib/s3-mirror/${c}-fullfilelist) ; then
        echo "=============================================================="
        echo -n "Starting at "
        date
        time $s3cmd $S3CMD_ARGS  \
    	       --cache-file /var/lib/s3-mirror/${c}.cache \
                   --delete-removed \
                   --delete-after \
                   --add-destination s3://s3-mirror-us-west-1.fedoraproject.org/pub/${c}/ \
                   --add-destination s3://s3-mirror-us-west-2.fedoraproject.org/pub/${c}/ \
                   --add-destination s3://s3-mirror-eu-west-1.fedoraproject.org/pub/${c}/ \
                   --add-destination s3://s3-mirror-ap-northeast-1.fedoraproject.org/pub/${c}/ \
                          ${tree}/${c}/ s3://s3-mirror-us-east-1.fedoraproject.org/pub/${c}/
        report=1
        cp -a ${tree}/${c}/fullfilelist /var/lib/s3-mirror/${c}-fullfilelist
        echo "lastrun=${curdate}" > /var/run/s3-mirror/lastrun
    fi
done


if [ ${report} -ne 0 ] ; then
    for target in ${targets} ; do
       report_mirror -c /etc/mirrormanager-client/report_mirror_${target}.conf --exclude-from /usr/local/etc/s3-mirror-excludes.txt
    done
    echo -n "Ending at "
    date
fi