forked from CANDY-LINE/docker-mysql-backup-cron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_list.sh
executable file
·49 lines (48 loc) · 1.32 KB
/
_list.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
#!/bin/bash
function list_backup_files {
TMP_OUT="/tmp/list"
rm -f ${TMP_OUT}
case $STORAGE_TYPE in
s3)
BUCKET_PREFIX=$BUCKET
if [ -n "$PREFIX" ]; then
BUCKET_PREFIX=$BUCKET/$PREFIX
fi
s3cmd --access_key=$ACCESS_KEY --secret_key=$SECRET_KEY --region=$REGION ls $BUCKET_PREFIX > ${TMP_OUT}
;;
swift)
CONTAINER_PREFIX=""
if [ -n "$PREFIX" ]; then
CONTAINER_PREFIX="--prefix ${PREFIX}"
fi
swift list $CONTAINER $CONTAINER_PREFIX > ${TMP_OUT}
;;
gcs)
prefix="gs://$GC_BUCKET/"
for p in `gsutil ls -r ${prefix}${PREFIX} | grep -v ":$"`; do
if [ -z "$p" ]; then
continue
fi
p2=$(echo ${p} | sed "s/${prefix//\//\\/}//g")
# remove gs://bucket-name/
echo "${p2}" >> ${TMP_OUT}
done
;;
local)
cd ${BACKUP_DIR}
find . -type f -name "*.sql.gz" | grep "^./${PREFIX}" > ${TMP_OUT}
;;
esac
if [ -z "${TS_PREFIX}" ]; then
LATEST_BACKUP=`cat ${TMP_OUT} | sort -r | head -1`
else
LATEST_BACKUP=`cat ${TMP_OUT} | grep ${TS_PREFIX} | sort -r | head -1`
fi
if [ -z "${TS_PREFIX}" ]; then
FILTERED_BACKUPS=`cat ${TMP_OUT}`
else
FILTERED_BACKUPS=`cat ${TMP_OUT} | grep ${TS_PREFIX}`
fi
ALL_BACKUP_FILES=`cat ${TMP_OUT} | sort -r`
rm -f ${TMP_OUT}
}