mirror of https://gitgud.io/fatchan/jschan.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
994 B
34 lines
994 B
#!/bin/bash
|
|
#
|
|
# Dumps jschan database to gzip archive, and archives the static folder
|
|
#
|
|
|
|
#variables, change me
|
|
APP_NAME="whatever"
|
|
MONGO_DATABASE="jschan"
|
|
MONGO_HOST=""
|
|
MONGO_PORT=""
|
|
MONGO_USER=""
|
|
MONGO_PASSWORD=""
|
|
TIMESTAMP=`date +%F-%H%M`
|
|
BACKUPS_DIR="/path/to/backups/folder/$APP_NAME"
|
|
|
|
#probably dont change these
|
|
DB_BACKUP_NAME="$APP_NAME-$TIMESTAMP.gz"
|
|
FILE_BACKUP_NAME="$APP_NAME-$TIMESTAMP-files.zip"
|
|
DB_ARCHIVE_PATH="$BACKUPS_DIR/$DB_BACKUP_NAME"
|
|
FILE_ARCHIVE_PATH="$BACKUPS_DIR/$FILE_BACKUP_NAME"
|
|
|
|
#create backup folder
|
|
mkdir -p $BACKUPS_DIR
|
|
|
|
#archive (no compression) files
|
|
zip -r -0 $FILE_ARCHIVE_PATH ./static
|
|
|
|
#dump database to .gz archive
|
|
mongodump --username $MONGO_USER --password $MONGO_PASSWORD --authenticationDatabase admin --db $MONGO_DATABASE --archive=$DB_ARCHIVE_PATH --gzip
|
|
rm -rf dump
|
|
|
|
#delete backups older than 7 days
|
|
sudo find $ARCHIVE_PATH -type f -name "*.gz" -mtime +7 -exec rm -f {} \;
|
|
sudo find $ARCHIVE_PATH -type f -name "*.zip" -mtime +7 -exec rm -f {} \;
|
|
|