Forked from ronanguilloux/script-bash-redmine-backups
Last active
August 25, 2016 10:57
-
-
Save rredkovich/886495d686b6d6a531df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# | |
# backup_redmine.sh | |
# modified by [email protected] | |
# from https://gist.github.com/ronanguilloux/6497272 | |
# | |
# Distributed under terms of the MIT license. | |
# /var/backups/redmine should exist | |
# $REDMINE_HOME/backups should also exist | |
# -- DB Type | |
# postgres or mysql | |
DB_TYPE="postgres" | |
# -- VARS | |
DAY=`date +"%Y%m%d"` | |
HOUR=`date +"%H%M"` | |
BACKUP_PATH=/var/backups/redmine | |
REDMINE_HOME=/home/redmine/redmine_code | |
REDMINE_DB_NAME=redmine | |
REDMINE_DB_USER=redmine | |
REDMINE_DB_PASS=Password | |
REDMINE_DB_BACKUP=$REDMINE_HOME/backups/redmine_$DB_TYPE.sql | |
REDMINE_BACKUP_NAME="redmine_"$DAY"_"$HOUR".tar.bz2" | |
REDMINE_BACKUP_HISTO="histo_redmine_"$DAY"_"$HOUR".tar.bz2" | |
REDMINE_BACKUP_LIVE_TIME=30 | |
REDMINE_BACKUP_HISTO_LIVE_TIME=365 | |
MODEL_BKP_DAILY=redmine_*.tar.bz2 | |
MODEL_BKP_HISTO=histo_redmine_*.tar.bz2 | |
# -- MySQL | |
if [ "$DB_TYPE" = "mysql" ]; then | |
echo "Snapshot backuping Redmine's MySQL db into Redmine instance..." | |
if ! mysqldump --user=$REDMINE_DB_USER --password=$REDMINE_DB_PASS $REDMINE_DB_NAME > $REDMINE_DB_BACKUP; then | |
echo "[!!ERROR!!] Failed to produce plain backup database $REDMINE_DB_NAME" 1>&2 | |
fi | |
echo "($REDMINE_DB_BACKUP) done." | |
echo | |
fi | |
# -- PostgreSQL | |
if [ "$DB_TYPE" = "postgres" ]; then | |
echo "Snapshot backuping Redmine's PostgreSQL db into Redmine instance..." | |
if ! pg_dump -Fp -U "$REDMINE_DB_USER" "$REDMINE_DB_NAME" | gzip > $REDMINE_DB_BACKUP; then | |
echo "[!!ERROR!!] Failed to produce plain backup database $REDMINE_DB_NAME" 1>&2 | |
fi | |
echo "($REDMINE_DB_BACKUP) done." | |
echo | |
fi | |
# -- Daily full Redmine dir backup | |
echo "Daily backuping Redmine's directory before sending it to a remote place..." | |
tar cjfP $BACKUP_PATH/$REDMINE_BACKUP_NAME $REDMINE_HOME | |
echo "($BACKUP_PATH/$REDMINE_BACKUP_NAME) done." | |
# -- Monthly full Redmine dir backup | |
TOMORROW=`date --date=tomorrow +%d` | |
if [ $TOMORROW -eq "1" ]; then | |
echo | |
echo "End of month : monthly backuping Redmine's directory..." | |
cp $BACKUP_PATH/$REDMINE_BACKUP_NAME $BACKUP_PATH/$REDMINE_BACKUP_HISTO | |
echo "($BACKUP_PATH/$REDMINE_BACKUP_HISTO) done." | |
fi | |
# -- Purging old outdated backups | |
echo | |
echo "Purging outdated backups..." | |
find $BACKUP_PATH/$MODEL_BKP_DAILY -mtime +$REDMINE_BACKUP_LIVE_TIME -exec rm {} \; | |
find $BACKUP_PATH/$MODEL_BKP_HISTO -mtime +$REDMINE_BACKUP_HISTO_LIVE_TIME -exec rm {} \; | |
echo "done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment