Search K
Appearance
Appearance
This script, if it exists, is run before/after all Admin or Reseller backups complete.
It is purposed to run after a large number of backups are created, hence it's not called for the User Level backups.
The parameters passed are the same values that are passed to DA via the task.queue for backup creation:
who is set to who except or selectedwhat is set to what_selectFor all_backups_post.sh, 2 additional variables are available:
This hook script is called after all Admin or Reseller restores.
ip_choice="select" is set, DA will restore the User with the selected IP, if set to "free_random" restore the User with a random free IPThis script is called just before a backup job is saved, either to a cron or to the task.queue (applicable to both creation and modification of backups as well as backup crons):
Data passed to the script will match exactly what is given to the task.queue upon backup creation, unless "when=cron" is set, then it will only be saved (no task.queue entry).
who is set to who except or selectedwhat is set to what_selectCalls to CMD_SITE_BACKUP / CMD_API_SITE_BACKUP have their own hook, /usr/local/directadmin/scripts/custom/cmd_site_backup_pre.sh.
And for CMD_USER_BACKUP / CMD_API_USER_BACKUP, the hook is /usr/local/directadmin/scripts/custom/cmd_user_backup_pre.sh.
Any non-zero exit code will echo any output to the GUI and abort whatever the action was.
Note, this is also called for the default GET to show the backup page, so ensure you're checking the method and action accordingly.
All variables that were passed via GET or POST will be included in the request.
DA will also set:
This script will be called, if it exists, just before the creation of the tar.gz file. It's called just after the assembly of the "backup" folder.
This hook will be called if there are any issues during the creation of the User Backup. This also includes errors that may arise for the Reseller/Admin Level portions of the User backup.
Ftp uploading is not part of the check as this is done outside of the backup function.
The user_backup_pre.sh script will be called before anything is done for user backup creation. A non-zero return value will abort user backup creation.
When skipping a suspended User, the user_backup_pre.sh won't be run, since the abort happens before that.
The user_backup_post.sh script will be called after each user tar.gz backup file is created (any format from any level).
Script to be called after the backup of each User only if the backup succeeded. Any failures in the process will prevent this script from being called.
This hook script is called after a DirectAdmin tar.gz backup restore fails.
The following cases to be included in the call of user_restore_fail_post.sh are mostly pre-check failures that occur before the actual restore process begins, and so are included in addition to failures during the actual "restore" process:
Note that the reason will include the
\n characters in it, as inserted into DA's message.
Note that owner and source_path will be empty strings if the restore is triggered by the User (User Level -> Create/Restore Backups). So be sure to check if owner is blank before trying to use the source_path (check it too).
The user_restore_pre.sh script is executed before a user restoration. Returning a non-zero exit value will abort the restore process and display any test/error.
The user_restore_post.sh hook script is executed after a user restoration.
The user_restore_post.sh will also have these additional environment variables:
This script is called after the restore of a User account, but just before the path is cleaned up.
This is called just before user_restore_post.sh, which is triggered after the temporary extracted data is cleaned up.
This script is to be used to prevent backups from being created if your disk usage is too high. This does not work with "System Backup" (it already has its own check). It works with all 3 Levels of DirectAdmin Backups (Admin, Reseller, and User).
/usr/local/directadmin/scripts/custom/user_backup_pre.sh#!/bin/sh
PARTITION=/dev/mapper/VolGroup00-LogVol00
MAXUSED=90
checkfree()
{
DISKUSED=`df -P $PARTITION | awk '{print $5}' | grep % | cut -d% -f1`
echo "$DISKUSED < $MAXUSED" | bc
}
if [ `checkfree` -eq 0 ]; then
echo "$PARTITION disk usage is above $MAXUSED% Aborting backup.";
exit 1;
fi
exit 0;Where you'd replace /dev/mapper/VolGroup00-LogVol00 with the filesystem you want to check. The MAXUSED value is the percentage threshold of the partition to be used. Chmod the script to 755.
To see the list of filesystem names, type:
df -hPwhere the filesystem names are on the far left (partition names on the right)
Credit for this script: Dmitry Sherman
If you wish to keep your load average below a certain point, and not allow backups to run right away if the load is over a certain point, the following script will help. It will check your load average before each backup file is created. If the load is too high, it will wait for 5 seconds, then check again. It will continue this process until the load is low enough, then create the backup. If the load is not below the threshold after 20 attempts, a non-zero value is returned and that user backup is skipped and an error is returned in DA.
To use this script, place the following code into the file:
/usr/local/directadmin/scripts/custom/user_backup_pre.sh#!/bin/sh
MAXTRIES=20
MAXLOAD=8.00
highload()
{
LOAD=`cat /proc/loadavg | cut -d\ -f1`
echo "$LOAD > $MAXLOAD" | bc
}
TRIES=0
while [ `highload` -eq 1 ];
do
sleep 5;
if [ "$TRIES" -ge "$MAXTRIES" ]; then
echo "system load above $MAXLOAD for $MAXTRIES attempts. Aborting.";
exit 1;
fi
((TRIES++))
done;
exit 0;Then chmod the new user_backup_pre.sh script to 755 and set the ownership to diradmin.
If you want to limit the number of backups a User can created, to say 5, then you can create the following custom script to enforce it:
/usr/local/directadmin/scripts/custom/user_backup_pre.shand add the code:
#!/bin/sh
MAX_BACKUPS=5
#check filename for /home/user/
U=`echo $file | cut -d/ -f3`
if [ "$U" != "$username" ]; then
#file is not in our /home, so is Reseller or Admin backup.
exit 0;
fi
#file is being created below this User.
C=`ls /home/$username/backups | wc -l`
if [ "$C" -ge "$MAX_BACKUPS" ]; then
echo "Too many backups. Delete some from /home/$username/backups before creating another.";
exit 1;
fi
exit 0;Now chmod the script to 755 and set the ownership to diradmin.
You can manually test the script like this:
file=/home/fred/backups/backup.tar.gz username=fred ./user_backup_pre.sh; echo $?;Which will either output 0, which means the script allowed creation, or the "Too many backups" error, followed by a "1", where 1 indicates the exit status is an error and the script tells DA to abort the backup.