Backup issues (renaming and copying)

jmd

Verified User
Joined
Jun 5, 2013
Messages
9
Hi,

I am wanting to preform an incremental admin backup locally and by ftp.
I am looking at the following for my backup regimen:

I want my locally created backups to contain a date in the filename:
http://help.directadmin.com/item.php?id=454

I want a local copy, and a remote copy of my backups, without running the backup twice:
http://help.directadmin.com/item.php?id=511

Will running these two together, in the same user_backup_post.sh file, have any conflict?
Basically, will it rename the backup then copy from tmp to the local admin_backups folder before sending it to the remote server?
I'm thinking the conflict will be where it has two different required paths. Should I be renaming it in the tmp location first before copying to the local admin_backups then sending renamed files to remote location with ftp?

the script:
Code:
#!/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

RESELLER=admin

#where do you want to save the local copy?
SAVE_PATH=/home/$RESELLER/admin_backups
#############

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

if [ "$BACKUP_PATH" = "$REQUIRED_PATH" ]; then
      NEW_FILE=${SAVE_PATH}/`echo $file | cut -d/ -f5`
      cp -fp $file $NEW_FILE
fi
exit 0;
 
I am wanting to preform an incremental admin backup locally and by ftp.
Am I missing something? DirectAdmin's admin level reseller backup doesn't create incremental backups.

Jeff
 
No, I'm just using the wrong terminology.
What I'm wanting to do is merge the two scripts together:

I want my locally created backups to contain a date in the filename:
http://help.directadmin.com/item.php?id=454
I want a local copy, and a remote copy of my backups, without running the backup twice:
http://help.directadmin.com/item.php?id=511


And I am asking for advice on how this will be written and if they conflict (as per code in first post).
 
So add some curl commands to your backup post to ftp it somewhere.

Code:
#!/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

RESELLER=admin

#where do you want to save the local copy?
SAVE_PATH=/home/$RESELLER/admin_backups
#############

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

if [ "$BACKUP_PATH" = "$REQUIRED_PATH" ]; then
      NEW_FILE=${SAVE_PATH}/`echo $file | cut -d/ -f5`
      cp -fp $file $NEW_FILE
fi

curl -T $NEW_FILE ftp://your-ftp-host/folder --user username:password

exit 0;
 
Last edited:
Hi SCSI,
Sorry about the delayed response but thankyou for your reply.

A great idea using curl within the script.

The second part of the script (copying locally before uploading) doesn't work and the backup fails. I haven't looked into why because if I'm saving locally and using curl to upload to the remote server I wouldn't really need the second part of the script. So if I cut that out I get the following:
Code:
#!/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

curl -T $NEW_FILE ftp://your-ftp-host/folder --user username:password

exit 0;

This works fine for saving all backup files in home/$RESELLER/admin_backups with the date in the new filename but it's not moving anything to the remote server.

If I just run the curl from the command line:
Code:
[B]curl -T (any local filename in preset working directory) [url]ftp://your-ftp-host/folder[/url] --user username:password[/B]
It moves the file to the remote server without a problem, so I can confirm the remote servers details are correct.

I've tried to add the curl command to the line just below mv $file $NEW_FILE (inside the same if statement) but I get the same result, no movement, just an empty remote server.

Does anyone have any ideas why nothing is moving?
 
Back
Top