-
Notifications
You must be signed in to change notification settings - Fork 10
/
backup-weekly
executable file
·37 lines (30 loc) · 1.03 KB
/
backup-weekly
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
#!/bin/bash
# This script rotates the oldest daily backup
# to weekly backup.
BACKUP_VOLUME=$1
BACKUP_MOUNT=$2
BACKUP_DEVICE="${BACKUP_VOLUME}"
BACKUP_RW_MOUNT="${BACKUP_MOUNT}/${BACKUP_VOLUME}_rw"
BACKUP_RO_MOUNT="${BACKUP_MOUNT}/${BACKUP_VOLUME}"
./make_backup_rw ${BACKUP_VOLUME} ${BACKUP_MOUNT} || exit 1
### Delete the oldest weekly backup, if it exists
#
if [ -d ${BACKUP_RW_MOUNT}/weekly.3 ] ; then
rm -rf ${BACKUP_RW_MOUNT}/weekly.3
fi
### Shift the middle snapshots(s) back by one, if they exist
if [ -d ${BACKUP_RW_MOUNT}/weekly.2 ] ; then
mv ${BACKUP_RW_MOUNT}/weekly.2 ${BACKUP_RW_MOUNT}/weekly.3 ;
fi
if [ -d ${BACKUP_RW_MOUNT}/weekly.1 ] ; then
mv ${BACKUP_RW_MOUNT}/weekly.1 ${BACKUP_RW_MOUNT}/weekly.2 ;
fi
if [ -d ${BACKUP_RW_MOUNT}/weekly.0 ] ; then
mv ${BACKUP_RW_MOUNT}/weekly.0 ${BACKUP_RW_MOUNT}/weekly.1 ;
fi
### Hard link oldest daily backup to weekly backup
#
if [ -d ${BACKUP_RW_MOUNT}/daily.3 ] ; then
cp -al ${BACKUP_RW_MOUNT}/daily.3 ${BACKUP_RW_MOUNT}/weekly.0
fi
./make_backup_ro ${BACKUP_VOLUME} ${BACKUP_MOUNT}