how to back-up public_html (only) in my server to a remote server

May 13, 2015 4k views
Linux Basics Linux Commands Apache DigitalOcean DigitalOcean Articles PHP Ubuntu

hi, i would like to know if there’s a way to back-up my publichtml directory only to a remote server.
note: i don’t want to create a snapshot.
only my public
if there’s an external service that would be cool

1 Answer

Compress the whole directory and transfer it to another server using SCP.

cd /var/backups
export FILE_DATE=`date +%Y%m%d-%H.%M.%S`
tar -czf public_html-$FILE_DATE.tar.gz /location/to/public_html
scp public_html-$FILE_DATE.tar.gz username@remote.server.ip:/remote/directory
  • is scp same as ssh?
    do i need to install anything?

  • Yes both are the same, SSH is for executing commands and SCP is for file management.

  • Is their a way to automate this line:

    scp publichtml-$FILEDATE.tar.gz username@remote.server.ip:/remote/directory

    cron possibly? And get it to send the latest file in the folder?


  • You can create a shell script inside /etc/cron.daily/ with the above commands and make it executable chmod +x filename. Also generate a passphraseless SSH key and copy the public key to the remote server. This will run the script every 24 hours.

    And get it to send the latest file in the folder?

    Do you want to backup only the modified files? If so you should try duplicity.

Have another answer? Share your knowledge.