-
Notifications
You must be signed in to change notification settings - Fork 0
/
pshBackupProjects.sh
69 lines (52 loc) · 1.52 KB
/
pshBackupProjects.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/sh
# set defaults if not passed in
backuptype=${1:-db}
itemcount=${2:-20}
sleepduration=${3:-20}
# fetch list of projects
platform project:list --host=ca-1.platform.sh --format=tsv > ID_LIST_RAW
# remove header if above
sed '1d' ID_LIST_RAW > tmpFile
mv tmpFile ID_LIST_RAW
# split into smaller files of x projects each
split -l $itemcount ID_LIST_RAW ID_LIST --additional-suffix=.process
# loop through each file
for file in "$WORKSPACE"/ID_LIST*.process; do
echo "Processing File $file.....";
while IFS= read -r line; do
IFS=$'\t' read -r -a parts <<< "$line"
PROJECT_ID="${parts[0]}"
echo "${PROJECT_ID}" >> ID_LIST;
NAME="${parts[1]}"
NAME="${NAME%\"}"
NAME="${NAME#\"}"
NAME="${NAME// /_}"
NAME="${NAME//./_}"
NAME="${NAME//\'/_}"
echo "${NAME}" >> DIR_LIST;
case "$backuptype" in
"db")
echo "Creating DB Backups for ${NAME} Project ID ${PROJECT_ID}"
BUILD_ID=dontKillMe bash -ex pshGetDB.sh "${NAME}" "${PROJECT_ID}" &
;;
"files")
echo "Creating Public File Backups for ${NAME} Project ID ${PROJECT_ID}"
BUILD_ID=dontKillMe bash -ex pshGetPublicFiles.sh "${NAME}" "${PROJECT_ID}" &
;;
"private")
echo "Creating Private Backups for ${NAME} Project ID ${PROJECT_ID}"
BUILD_ID=dontKillMe bash -ex pshGetPrivateFiles.sh "${NAME}" "${PROJECT_ID}" &
;;
esac
done < $file
# wait a while for next batch
sleep $sleepduration
done
# save last processed
cp ID_LIST_RAW ID_LIST_RAW.last
cp DIR_LIST DIR_LIST.last
# clean up
rm DIR_LIST
rm ID_LIST
rm ID_LIST_RAW
rm ID_LIST*.process