forked from CANDY-LINE/docker-mysql-backup-cron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_delete.sh
executable file
·47 lines (42 loc) · 844 Bytes
/
_delete.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
#!/bin/bash
. /_list.sh
function delete {
case $STORAGE_TYPE in
s3)
s3cmd --access_key=$ACCESS_KEY --secret_key=$SECRET_KEY --region=$REGION del $BUCKET/$1
;;
swift)
swift delete $CONTAINER $1
;;
gcs)
gsutil rm -fr gs://$GC_BUCKET/$1
;;
local)
rm -f ${BACKUP_DIR}/$1
;;
esac
}
list_backup_files
if [ -n "${LATEST_BACKUP}" ]; then
for f in ${FILTERED_BACKUPS}
do
if [ ${f} != "${LATEST_BACKUP}" ]; then
delete ${f}
fi
done
fi
if [ -n "${ALL_BACKUP_FILES}" ]; then
NUM_FILES=0
TODAY=$(date +%Y-%m-%d)
for f in ${ALL_BACKUP_FILES}
do
if [ `echo ${f} | grep ${TODAY}` ]; then
continue
fi
let NUM_FILES=NUM_FILES+1
if [[ "${NUM_FILES}" -le "${MAX_DAILY_BACKUP_FILES}" ]]; then
continue;
fi
delete ${f}
done
fi