-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathbackup_artificial.sh
More file actions
executable file
·65 lines (63 loc) · 3.97 KB
/
backup_artificial.sh
File metadata and controls
executable file
·65 lines (63 loc) · 3.97 KB
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
#!/bin/bash
# Safer backup of artificial (very large IDs) rows for a specific DB.
# Behavior preserved; improved quoting and error handling.
set -euo pipefail
if [ ! -z "${NOBACKUP:-}" ]
then
exit 0
fi
if [ -z "${1:-}" ]
then
echo "$0: you need to provide database name as an argument"
exit 1
fi
db="$1"
if [ "$db" = "devstats" ]
then
exit 0
fi
cd /tmp || exit 1
function finish {
cd /tmp || true
rm -f -- "$db".* || true
}
trap finish EXIT
db.sh psql "$db" -tAc "\\copy (select * from gha_events where id > 281474976710656) TO '/tmp/$db.events.tsv'" || exit 2
db.sh psql "$db" -tAc "\\copy (select * from gha_payloads where event_id > 281474976710656) TO '/tmp/$db.payloads.tsv'" || exit 3
db.sh psql "$db" -tAc "\\copy (select * from gha_issues where event_id > 281474976710656) TO '/tmp/$db.issues.tsv'" || exit 4
db.sh psql "$db" -tAc "\\copy (select * from gha_pull_requests where event_id > 281474976710656) TO '/tmp/$db.prs.tsv'" || exit 5
db.sh psql "$db" -tAc "\\copy (select * from gha_milestones where event_id > 281474976710656) TO '/tmp/$db.milestones.tsv'" || exit 6
db.sh psql "$db" -tAc "\\copy (select * from gha_issues_labels where event_id > 281474976710656) TO '/tmp/$db.labels.tsv'" || exit 7
db.sh psql "$db" -tAc "\\copy (select * from gha_issues_assignees where event_id > 281474976710656) TO '/tmp/$db.issue_assignees.tsv'" || exit 8
db.sh psql "$db" -tAc "\\copy (select * from gha_pull_requests_assignees where event_id > 281474976710656) TO '/tmp/$db.pr_assignees.tsv'" || exit 9
db.sh psql "$db" -tAc "\\copy (select * from gha_pull_requests_requested_reviewers where event_id > 281474976710656) TO '/tmp/$db.pr_reviewers.tsv'" || exit 10
db.sh psql "$db" -tAc "\\copy (select * from gha_issues_events_labels where event_id > 281474976710656) TO '/tmp/$db.issues_events_labels.tsv'" || exit 11
db.sh psql "$db" -tAc "\\copy (select * from gha_texts where event_id > 281474976710656) TO '/tmp/$db.texts.tsv'" || exit 12
rm -f -- "$db".tar* || exit 13
tar cf "$db".tar "$db".*.tsv || exit 14
xz "$db".tar || exit 15
mv "$db".tar.xz /var/www/html/ || exit 16
db.sh psql $db -tAc "\copy (select * from gha_events where id > 281474976710656) TO '/tmp/$db.events.tsv'" || exit 2
db.sh psql $db -tAc "\copy (select * from gha_payloads where event_id > 281474976710656) TO '/tmp/$db.payloads.tsv'" || exit 3
db.sh psql $db -tAc "\copy (select * from gha_issues where event_id > 281474976710656) TO '/tmp/$db.issues.tsv'" || exit 4
db.sh psql $db -tAc "\copy (select * from gha_pull_requests where event_id > 281474976710656) TO '/tmp/$db.prs.tsv'" || exit 5
db.sh psql $db -tAc "\copy (select * from gha_milestones where event_id > 281474976710656) TO '/tmp/$db.milestones.tsv'" || exit 6
db.sh psql $db -tAc "\copy (select * from gha_issues_labels where event_id > 281474976710656) TO '/tmp/$db.labels.tsv'" || exit 7
db.sh psql $db -tAc "\copy (select * from gha_issues_assignees where event_id > 281474976710656) TO '/tmp/$db.issue_assignees.tsv'" || exit 8
db.sh psql $db -tAc "\copy (select * from gha_pull_requests_assignees where event_id > 281474976710656) TO '/tmp/$db.pr_assignees.tsv'" || exit 9
db.sh psql $db -tAc "\copy (select * from gha_pull_requests_requested_reviewers where event_id > 281474976710656) TO '/tmp/$db.pr_reviewers.tsv'" || exit 10
db.sh psql $db -tAc "\copy (select * from gha_issues_events_labels where event_id > 281474976710656) TO '/tmp/$db.issues_events_labels.tsv'" || exit 11
db.sh psql $db -tAc "\copy (select * from gha_texts where event_id > 281474976710656) TO '/tmp/$db.texts.tsv'" || exit 12
rm -f $db.tar* || exit 13
echo "Creating backup archive $db.tar.xz"
tar cf $db.tar $db.*.tsv || exit 14
if [ -z "${FASTXZ}" ]
then
echo "xztting backup archive $db.tar.xz with default compression"
xz $db.tar || exit 15
else
echo "xztting backup archive $db.tar.xz with fast compression"
xz -1 $db.tar || exit 16
fi
cp $db.tar.xz /var/www/html/ || echo 'Could not copy backup to /var/www/html/ (this is fine)'
cp $db.tar.xz /root/ || echo 'Could not copy backup to /root/ (this is fine)'