I have been thinking about allowing customers to download their own backup, so I deicide to wrote this.
It's very simple as I'm not very skilled with shell programming, but does the job.
Create file /move-backup-to-users.sh, paste the code below and chmod to 700:
Create the file /scripts/postcpbackup (if doesn't exists) and paste this line:Code:#!/bin/sh BACKUPDIR=/home/backup #without trailing slash #don't change if you don't know what it is for BACKUPTYPES=$(ls $BACKUPDIR/cpbackup/) USERS=$(ls /home/) #users DATE=$(date) for u in $USERS do for t in $BACKUPTYPES do if [ -f $BACKUPDIR/cpbackup/$t/$u.tar.gz ]; then mv -f $BACKUPDIR/cpbackup/$t/$u.tar.gz /home/$u/backup-$t-$u.tar.gz chown $u:$u /home/$u/backup-$t-$u.tar.gz if [ -f /home/$u/backup_email.txt ]; then source /home/$u/backup_email.txt /bin/mail -s "$SUBJECT" "$EMAIL" < $MESSAGE rm $MESSAGE fi # debug echo $BACKUPDIR/cpbackup/$t/$u.tar.gz /home/$u/backup-$t-$u.tar.gz$n echo chown $u:$u /home/$u/backup-$t-$u.tar.gz echo $n # debug else echo "File not found $BACKUPDIR/cpbackup/$t/$u.tar.gz" fi done done
Create the file /scripts/precpbackup (if doesn't exists) and paste this:Code:/move-backup-to-users.sh
Save this as txt to /home/username/backup_email.txt if you want the user to be emailedCode:#!/bin/sh #don't change if you don't know what it is for USERS=$(ls /home/) #users BACKUPTYPES=daily weekly monthly for u in $USERS do for t in $BACKUPTYPES do if [ -f $BACKUPDIR/cpbackup/$t/$u.tar.gz ]; then rm /home/$u/backup-$t-$u.tar.gz fi done done
Since I have customer from three different countries, I have translated this to other languages as well
Go to WHM -> Backup -> Configure Backup -> Check: Execute Pre/Post Backup ScriptSUBJECT="New Backup Available"
EMAIL="user@email.com"
MESSAGE="/tmp/emailmessage.txt"
echo "$DATE" >> $MESSAGE
echo "This is an email to tell you that a new backup file is available: /home/$u/backup-$t-$u.tar.gz" >> $MESSAGE
echo "We recommend that you download this backup from time to time" >> $MESSAGE
echo "If the backup is too large, try to download old things or asks us to exclude large directories" >> $MESSAGE
echo "or directories that you don't need to backup" >> $MESSAGE
/scripts/precpbackup
/scripts/postcpbackup
Test by running /./move-backup-to-users.sh and /scripts/cpbackup
Feel free to modify, share, improve.


LinkBack URL
About LinkBacks
Reply With Quote