-
-
Notifications
You must be signed in to change notification settings - Fork 345
Expand file tree
/
Copy pathcreate-dumps.sh
More file actions
executable file
·53 lines (39 loc) · 1000 Bytes
/
create-dumps.sh
File metadata and controls
executable file
·53 lines (39 loc) · 1000 Bytes
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
#!/usr/bin/env bash
set -e
source /home/bookbrainz/bookbrainz-site/scripts/config.sh
# Switch directory
pushd /home/bookbrainz/data/dumps
DUMP_FILE=bookbrainz-dump-`date -I`.sql
echo "Creating data dump..."
# Dump new backup to /tmp
pg_dump\
-h $POSTGRES_HOST \
-p $POSTGRES_PORT \
-U bookbrainz \
-T _editor_entity_visits\
-T user_collection*\
--serializable-deferrable\
bookbrainz > /tmp/$DUMP_FILE
echo "Dump created!"
# Compress new backup and move to dump dir
echo "Compressing..."
rm -f /tmp/$DUMP_FILE.bz2
bzip2 /tmp/$DUMP_FILE
mv /tmp/$DUMP_FILE.bz2 .
echo "Compressed!"
echo "Removing old dumps..."
rm -f /tmp/*.sql
# Remove backups older than 8 days
find ./ -name '*.sql.bz2' -type f -mtime +7 -print | xargs /bin/rm -f
echo "Done!"
rm -f latest.sql.bz2
ln -s $DUMP_FILE.bz2 latest.sql.bz2
# Generate hashes
echo "Generating hashes..."
md5sum *.sql.bz2 > MD5SUMS
sha256sum *.sql.bz2 > SHA256SUMS
echo "Done!"
chown bookbrainz:bookbrainz ./*
chmod 644 ./*
popd
exit 0