Created
May 2, 2019 04:05
-
-
Save rwbaumg/e00fd926bd7ca636c8b79ee2edb5d2fc to your computer and use it in GitHub Desktop.
Simple backup script for Trac projects.
This file contains hidden or 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 | |
| # 0x19e Networks | |
| # This script automates backing up a Trac project | |
| # settings | |
| PROJECTS_ROOT="/storage/trac/projects" | |
| BACKUP_ROOT="/storage/trac/backup" | |
| if [[ -z "$1" ]]; then | |
| echo "Usage: $0 <project name>" >&2 | |
| exit 1 | |
| fi | |
| if [[ $EUID -ne 0 ]]; then | |
| echo "This script must be run as root" >&2 | |
| exit 1 | |
| fi | |
| # configure variables | |
| PROJECT_PATH="$PROJECTS_ROOT/$1" | |
| BACKUP_PATH="$BACKUP_ROOT/$1" | |
| echo "Creating backup for $PROJECT_PATH ..." | |
| # backup the project | |
| trac-admin "$PROJECT_PATH" hotcopy "$BACKUP_PATH" | |
| # compress the backup | |
| BACKUP_NAME="trac-$(echo $1 | sed -e 's/ /-/g')-$(date '+%Y-%m-%d').tar.gz" | |
| BACKUP_ARCHIVE="$BACKUP_ROOT/$BACKUP_NAME" | |
| tar -zcf "$BACKUP_ARCHIVE" -C "$BACKUP_ROOT/" "$1" | |
| # remove the backup folder | |
| rm -rf "$BACKUP_PATH" | |
| # set permissions | |
| chmod 600 "$BACKUP_ARCHIVE" | |
| chown root:adm "$BACKUP_ARCHIVE" | |
| echo "$PROJECT_PATH backed up to $BACKUP_ARCHIVE" | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment