forked from bamford/lvm-rsync-backup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup-monthly
executable file
·37 lines (30 loc) · 1.04 KB
/
backup-monthly
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 weekly backup
# to monthly 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 monthly backup, if it exists
#
if [ -d ${BACKUP_RW_MOUNT}/monthly.3 ] ; then
rm -rf ${BACKUP_RW_MOUNT}/monthly.3
fi
### Shift the middle snapshots(s) back by one, if they exist
if [ -d ${BACKUP_RW_MOUNT}/monthly.2 ] ; then
mv ${BACKUP_RW_MOUNT}/monthly.2 ${BACKUP_RW_MOUNT}/monthly.3 ;
fi
if [ -d ${BACKUP_RW_MOUNT}/monthly.1 ] ; then
mv ${BACKUP_RW_MOUNT}/monthly.1 ${BACKUP_RW_MOUNT}/monthly.2 ;
fi
if [ -d ${BACKUP_RW_MOUNT}/monthly.0 ] ; then
mv ${BACKUP_RW_MOUNT}/monthly.0 ${BACKUP_RW_MOUNT}/monthly.1 ;
fi
### Hard link oldest weekly backup to monthly backup
#
if [ -d ${BACKUP_RW_MOUNT}/weekly.0 ] ; then
cp -al ${BACKUP_RW_MOUNT}/weekly.3 ${BACKUP_RW_MOUNT}/monthly.0
fi
./make_backup_ro ${BACKUP_VOLUME} ${BACKUP_MOUNT}