I've got to make a cron job of transfering over 100 backup .tar.gz files to ftp backup server. Stuck upon combining find command
find /home/backup -mtime -1 -mmin +59 -type f -name "*.tar.gz*"
this part works fine, and script part:
#!/bin/sh
USERNAME="user"
PASSWORD="password"
SERVER="someip"
FILE="/home/backup"
DATE="`date +%Y-%m-%d-%H.%M.%S `"
BACKUPDIR="/backup/${DATE}/"
ftp -inv $SERVER <<EOF
user $USERNAME $PASSWORD
mkdir $BACKUPDIR
cd $BACKUPDIR
mput $FILE/*.tar.gz*
quit
EOF
for this
00 12 * * * find /home/backup -mtime -1 -mmin +59 -type f -name "*.tar.gz*" -exec /root/ftp.sh {} \;
doesn't work. No scp/ssh advice please) have to do it with ftp.
Based on Ljm Dullaart answer working script looks like:
yet can be done using a different loop:
both will do for uploading backup files sorted by date via ftp.
I advise you to make the crontab command smaller. Not that it shouldn't working your way, but it will be easier to understand what is happening.
and
This will work, as long as you are sure that your tar.gz filenames don't have spaces in them.
On the other hand, if you are able to do the ftp with an mput, there is no reason to do the find at all:
So, you would either use
find
to loop over the files, which is a good idea if there are multiple levels of directories where the tar.gz files are, or you would usemput
inftp
if all the archives are always in the same directory.