I want my locally created backups to contain a date in the filename


Enter Your Query:
Use '%' for wildcards and quotes for "exact phrases"


Top Level » DirectAdmin » Backup & Restore Process

I want my locally created backups to contain a date in the filenameLast Modified: Oct 15, 2012, 11:06 pm
If you'd like to change the backup filename from:

user.admin.username.tar.gz

to be:

user.admin.username.2012-10-15-23-32.tar.gz


where the date represents YYYY-MM-DD-HH-MM, eg:
Mon Oct 15 23:32:13 MDT 2012

You can create a script called:

/usr/local/directadmin/scripts/custom/user_backup_post.sh

and fill it with the following code.
The code below only sets the date format for locally created backups, created by "admin" in /home/user/admin_backups, but can be changed.

#!/bin/sh

#set this as needed
RESELLER=admin

BACKUP_PATH=`echo $file | cut -d/ -f1,2,3,4`
REQUIRED_PATH=/home/$RESELLER/admin_backups

if [ "$BACKUP_PATH" = "$REQUIRED_PATH" ]; then
   if [ "`echo $file | cut -d. -f4,5`" = "tar.gz" ]; then
       NEW_FILE=`echo $file | cut -d. -f1,2,3`.`date +%F-%H-%M`.tar.gz
       if [ -s "$file" ] && [ ! -e "$NEW_FILE" ]; then
           mv $file $NEW_FILE
       fi
   fi
fi
exit 0;

Then chmod the script to 755.
 
Related Helpfiles
I want a local copy, and a remote copy of my backups, without running the backup twice

© 2018 JBMC Software, Suite 173  3-11 Bellerose Drive, St Albert, AB  T8N 1P7  Canada.  Mon-Fri 9AM-5PM MST