-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpanel_cron
28 lines (19 loc) · 982 Bytes
/
cpanel_cron
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
#!/usr/bin/env bash
# To perform a cPanel backup for the specified cPanel account via CRON.
# Once done, remove any backups in the destination location older than 5 days.
# Last, copy the newly created back to the destination, changing the name to match the backup date/time.
# Create a backup of the specified user and then move it to the /backupdrive location, deleting the oldest in the process.
USER=$1
/scripts/pkgacct $USER
# Make sure the backup completed successfully.
if [ $? -ne 0 ]; then
echo "Backup for $USER failed."
echo "Aborting backup process."
exit 1
fi
# The backup completed without an error reported. We can delete the oldest backup in /backupdrive/pickeringtoyota.
# Find and remove any files older than 5 days.
find /backupdrive/$USER/ -type f -name '*.tar.gz' -mtime +5 -exec rm -f {} \;
# Now, move the new backup to the backup drive.
mv /home/cpmove-${USER}.tar.gz /backupdrive/${USER}/${USER}_$(date '+%Y-%m-%d').tar.gz
exit 0