This repository has been archived by the owner on Mar 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup.sh
executable file
·48 lines (34 loc) · 1.69 KB
/
backup.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
#!/bin/sh
: ${DATABASE_HOST:?"Need to set DATABASE_HOST"}
: ${DATABASE_PORT:?"Need to set DATABASE_PORT"}
: ${DATABASE_USERNAME:?"Need to set DATABASE_USERNAME"}
: ${DATABASE_PASSWORD:?"Need to set DATABASE_PASSWORD"}
: ${LOGS_FOLDER:?"Need to set LOGS_FOLDER"}
: ${BACKUP_FOLDER:?"Need to set BACKUP_FOLDER"}
: ${BACKUP_RETENTION:=7}
: ${DEMO_RETENTION:=180}
mkdir -p $BACKUP_FOLDER/logs
mkdir -p $BACKUP_FOLDER/backups
TODAY=$(date +"%Y-%m-%d")
echo "Running Backup for $TODAY"
echo "Copying logs older than a day to backup (Skipping Existing files)"
cd $LOGS_FOLDER
find . -mtime +1 -exec rsync --ignore-existing -Rq '{}' $BACKUP_FOLDER/logs \;
echo "Creating temporary folder for Database & etcd dump."
TMP_DIR=/tmp/backup
mkdir $TMP_DIR
echo "Temp dir created: $TMP_DIR"
mkdir -p $TMP_DIR/db
echo "Dumping Forums DB to data.sql file."
mariadb-dump -h $DATABASE_HOST -P $DATABASE_PORT -u $DATABASE_USERNAME -p$DATABASE_PASSWORD yogstation_forums > $TMP_DIR/db/forums.sql
echo "Dumping Game DB to data.sql file."
mariadb-dump -h $DATABASE_HOST -P $DATABASE_PORT -u $DATABASE_USERNAME -p$DATABASE_PASSWORD yogstation_copy > $TMP_DIR/db/game.sql
echo "Dumping Wiki DB to data.sql file."
mariadb-dump -h $DATABASE_HOST -P $DATABASE_PORT -u $DATABASE_USERNAME -p$DATABASE_PASSWORD yogstation_wiki > $TMP_DIR/db/wiki.sql
# TODO: etcd dump
echo "Compress dumped data into zip archive."
zip -qr $BACKUP_FOLDER/backups/backup-$TODAY.zip $TMP_DIR
echo "Delete backups older than $BACKUP_RETENTION days."
find $BACKUP_FOLDER/backups -type f -mtime +$BACKUP_RETENTION -name '*.zip' -exec rm -- '{}' \;
echo "Delete demos older than $DEMO_RETENTION days."
#find . -mtime +$DEMO_RETENTION -name demo.txt.gz -exec rm {} \;