0

How i can transfer my backup to a remote server using ftp protocol and ftp command in a single command line?

My mysql dump command

mysqldump -u _admin -p'pass&word' _maindb --add-drop-table --ignore-table=_maindb.emailstatstics > backup$(date '+%d_%m_%y_%H_%M').sql

And ftp like:

ftp 64.xx.xx.xx 
myUserName
myPassword
put myMysqlBackup.sql

I need this command to executed in cronjobs in directadmin

3 Answers 3

1

This will get the file uploaded. You can put the two lines into a shell script and make it executable and you should have no problem using it from a crontab. Just make sure you use the absolute path to the output file.

ftp -u ftp://myUserName:[email protected] myMysqlBackup.sql
4
  • I need to transfer it after the backup has complete. how to write in a shell? im beginer to linux command
    – Hamidreza
    Jul 30, 2012 at 14:14
  • 1
    Just put the two lines in a file somewhere with a .sh extension and add #!/bin/sh as a separate line at the top. This tells the loader to use the sh shell to run your script. Then you just need to mark as executable with chmod +x /path/to/script.sh. Jul 30, 2012 at 15:11
  • 1
    Sorry, noticed you mentioned DirectAdmin. If you put this script in your user's home directory (outside of the web root - this is important) then you should be able to specify the full path to the script as the "command" in DirectAdmin. Jul 30, 2012 at 15:14
  • Your ftp command doesn't work as i needed, but your suggestion to create a shell was helpful.
    – Hamidreza
    Jul 31, 2012 at 6:55
1

Presumably:

FILENAME=backup$(date '+%d%m_%y_%H_%M').sql ; mysqldump -u _admin -p'pass&word' _maindb --add-drop-table --ignore-table=maindb.emailstatstics > $FILENAME ; scp $FILENAME USERNAME:[email protected]/.
2
  • It does not work for me, ftp 64.xx.xx.xx myUserName myPassword put $FILENAME does not do any thing, i give this message usage: ftp host-name [port]
    – Hamidreza
    Jul 30, 2012 at 14:35
  • Ah .. I assumed the ftp command you wrote in your question was a working one. I'll amend the response then.
    – troelskn
    Jul 31, 2012 at 9:08
0

Try this:

#/bin/bash
archive=$(date +%Y-%m-%d-%H-%M).gz
mysqldump --all-databases | gzip -9 >  $archive
HOST=backupserver
USER=user
PASS=password
ftp -inv $HOST << EOF
user $USER $PASS
put $archive
bye
EOF
rm -f archive

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.