This can be used for example to retrieve a copy of one’s website, blog, or other files on a script or cron job. You will need to have your SSH identity files for passwordless login.
#!/bin/bash #-- start config # Local Directory for backups. A date-specific folder is created under this directory for the files. LD=~/website_files/backups # Remote Directory to retrieve. Files are retrieved recursively starting here. Hidden files are included. # Must be full path, don't use ~ shortcut. RD=/home/www # Path to SSH ID file (private key) ID=~/.ssh/id_rsa # USERname to login as USER=username # HOST to login to HOST=example.com #--- end config BD="$LD/`date +%F`" mkdir $BD scp -ri $ID [email protected]$HOST:$RD/. $BD