-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathclean-orphan-backups.sh
More file actions
executable file
·26 lines (24 loc) · 957 Bytes
/
clean-orphan-backups.sh
File metadata and controls
executable file
·26 lines (24 loc) · 957 Bytes
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
#!/bin/bash
# +----+----+----+----+
# | | | | |
# Author: Mark David Scott Cunningham | M | D | S | C |
# +----+----+----+----+
# Created: 2016-09-11
# Updated: 2017-01-24
#
# Purpose: Cleaning orphaned newer style backups, for accounts not on the server.
#
if [[ -d /backup/cpbackup/ ]]; then
echo "Cleaning Legacy Backups"
backuplist=$(find /backup/cpbackup/{daily,weekly,monthly}/ -type f -name "*.tar.gz" 2>/dev/null)
else
echo "Cleaning Modern Backups"
backuplist=$(find /backup/{,weekly,monthly}/*/accounts/ -type f -name "*.tar.gz" 2>/dev/null)
fi
for x in $backuplist; do
user=$(basename $x .tar.gz);
if [[ ! $(grep $user /etc/domainusers) ]]; then
echo "Removed orphaned backup :: $user :: $x";
rm -f $x;
fi;
done