-
Notifications
You must be signed in to change notification settings - Fork 15
/
purge-user-backup.sh
executable file
·65 lines (52 loc) · 1.56 KB
/
purge-user-backup.sh
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
source $CURRENT_DIR/config.ini
# This script will remove incremental backups for the given user.
USAGE="purge-user-backup.sh user"
# Assign arguments
USER=$1
# Set script start time
START_TIME=`date +%s`
# Set user repository
USER_REPO=$REPO_USERS_DIR/$USER
##### Validations #####
if [ -z $1 ]; then
echo "!!!!! This script needs 1 argument: user"
echo "---"
echo "Usage example:"
echo $USAGE
exit 1
fi
# Check if user repo exist
if [ ! -d "$USER_REPO" ]; then
echo "!!!!! User $USER has no backup repository or no backup has been executed yet. Aborting..."
echo "---"
echo "Available user repositories:"
ls $REPO_USERS_DIR
echo "---"
echo "Usage example:"
echo $USAGE
exit 1
fi
echo "########## BACKUP REPOSITORY FOR USER $USER FOUND, PROCEEDING WITH PURGE ##########"
echo "!!!!! This will remove all incremental backups for user $USER."
read -p "Are you sure you want to purge $USER_REPO repository? " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
[[ "$0" = "$BASH_SOURCE" ]]
echo
echo "########## PROCESS CANCELED ##########"
exit 1
fi
echo "-- Removing user $USER repo: $USER_REPO"
if [ -d "$USER_REPO" ]; then
rm -rf $USER_REPO
fi
echo "If the user still exist in the system the incremental backups will begin in the next run."
echo
echo "$(date +'%F %T') #################### USER $USER REPOSITORY PURGE COMPLETE ####################"
END_TIME=`date +%s`
RUN_TIME=$((END_TIME-START_TIME))
echo "-- Execution time: $(date -u -d @${RUN_TIME} +'%T')"
echo