I'm working in a location with a physical server, and the company I am working for is in a different location, and has a cloud server with a different address.

Database backups work using automysqlbackup script in the cloud server also. But the database backups that I want to pull from the cloud server is quite huge and cannot be exported to my local server using phpMyAdmin.

So can I use the scp command in the crontab to pull the backed up database daily into my local server? , i.e :

* * * * * scp -r [email]root@cloudservername:/backups/databasename.sql.gz[/email]

Thanks.

Not sure if the cron environment or the crontab itself will support the use of scp in that shell the way you want to use it. I'd suggest pulling the scp command out into some script file and then running the script, after you explicitly set any required or assumed environment variables. Something like:

* * * * * /path/to/script.sh

where /path/to/script.sh is your new script and inside it, you have:

#!/bin/bash
export ENVIRONMENT_VAR=foo
#whatever else you need
scp -r root@cloudservername:/backups/databasename.sql.gz > /tmp/output.log

What does export ENVIRONMENT_VAR=foo do, and what do I actually add in #whatever else you need?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.