source: OpenWorkouts-current/bin/zeo_backup @ 8ee2af5

current
Last change on this file since 8ee2af5 was d98641b, checked in by Borja Lopez <borja@…>, 5 years ago

Fixed permissions on the helper scripts under bin/

  • Property mode set to 100755
File size: 2.4 KB
Line 
1#!/bin/sh
2#
3# Script to backup the ZODB served by the ZEO server
4#
5# The path to the db file is already set appropiately (relative), but you have
6# to adjust the path to the backups directory.The user running the script needs
7# write and exec permissions on such directory.
8#
9# This script will create per-month directories where a first full backup,
10# then incremental backups, will be saved (2013-10, 2013-11, etc)
11#
12# When doing the first full backup It will create a symlink called "latest",
13# pointing to the latest backup
14#
15
16here=`dirname $0`
17db="${here}/../var/zeo/Data.fs"
18backups=/home/backups/zodb/openworkouts
19month=`date "+%Y-%m"`
20now=`date "+%Y%m%d-%H%M%S"`
21
22
23usage()
24{
25    echo "$0 full | incremental | help"
26    echo ""
27    echo " full: performs a full backup, initializing a new backup directory"
28    echo "       for the current month"
29    echo ""
30    echo " incremental: runs another backup in an existing backup directory"
31    echo "              adding only new changes from the database"
32    echo ""
33    echo " help: shows this message"
34}
35
36
37init_backup_dir()
38{
39    # Creates a new backup directory using the current month as the name.
40    # Also creates a symlink called "latest" pointing to this directory
41    if [ -d ${backups}/${month} ]; then
42        # move aside any previous backup directory
43        echo "[ Warning ] A previous backup has been found for ${month}, "
44        echo "            saving it as ${backups}/${month}.${now}"
45        mv ${backups}/${month} ${backups}/${month}.${now}
46    fi
47    mkdir -p ${backups}/${month}
48    if [  -L ${backups}/latest ]; then
49        rm ${backups}/latest
50    fi
51    ln -sf ${backups}/${month} ${backups}/latest
52}
53
54
55if [ ! -f ${db} ]; then
56    echo "[ Error ] Database file ${db} not found, aborting"
57    exit 1
58fi
59
60if [ ! -d ${backups} ]; then
61    echo "[ Warning ] Backups directory not found, creating it"
62    mkdir -p ${backups}
63fi
64
65if [ ! -d ${backups} ]; then
66    echo "[ Error ] Backups directory still not found, aborting"
67    exit 1
68fi
69
70
71case "$1" in
72    'full')
73        echo "Creating new full backup: ${backups}/${month}"
74        init_backup_dir
75        repozo -B -v -F -f ${db} -r ${backups}/latest -z
76        ;;
77    'incremental')
78        echo "Adding incremental backup to ${backups}/latest"
79        if [ ! -d ${backups}/${month} ]; then
80            # Current month backup does not exist, start with a full backup
81            echo "[ Error ] Latest full backup not found, please run a full"
82            echo "          backup first"
83            exit 1
84        fi
85        repozo -B -v -f ${db} -r ${backups}/latest -z
86        ;;
87    *)
88        usage
89esac
Note: See TracBrowser for help on using the repository browser.