How to backup the remote files in Linux / UNIX

Q. How do I make remote backups under Linux? I’ve CentOS 5 Linux server located in remote data center and I’d like to backup it to local or another server?

A. Both Linux / UNIX come with handy tools to make secure remote backups. You can use tool called rsync for automating remote backups of your Linux, UNIX, Windows server, Mac OS X and BSD systems. rsync is a program with many more options and uses the rsync remote-update protocol to greatly speed up file transfers when the destination file is being updated.

Task: Copy files / backup files from remote Linux server

Let us say you would like to backup files from remote server called and directory called /home/vivek to local directory called /backup, type the command as follows on local system:
$ rsync -avz -e ssh /backup
You need to supply password for vivek user.

Task: Exclude files from backup

You can also skip few files from backup. Let us say you don’t want to backup all C source code file, enter:
$ rsync --exclude '*.cpp' -avz -e ssh /backup

Task: Automatic backup using a shell script

SSH always prompts for a password. To automate process via a shell script you need to remove password using SSH key i.e. generate passphraseless keys, enter (type at local system):
$ ssh-keygen -t dsa
When asked for to enter passphrase, just press [ENTER] key twice. Now copy public key to remote server:
$ scp ~/.ssh/
Now you can login without a password. For more information see – howto setup SSH with DSA public key authentication and RSA key authentication for password less login.

Now create a simple shell script as follows:
$ vi
Append code:
rsync --exclude '*.cpp' --exclude '*.log' -avz -e ssh /backup

Setup executable permission using chmod command:
$ chmod +x
Use cron to command to backup remote server:
$ crontab -e
Make a backup everyday:
@daily /path/to/
Save and close the file.

🐧 Please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
3 comments… add one
  • Margie Ludlam Feb 2, 2008 @ 23:21


    Does using rsync to back up Linux/Unix allow open files backup?


  • matt Jun 9, 2008 @ 6:05

    Thanks so much for this script, I have a serveral web servers whose htdocs are finally safe.

    I have a real few real estate sites with hundreds of thousands of images that I don’t need to back up, they come from the MLS depot every night. So, I tried excluding an entire directory, to my surporse, it works great, thought I would share.
    --exclude '/unwanted_directory/'

    Thanks again,


  • IAmWEC Oct 24, 2011 @ 2:56

    Is there any way that I can, say, tar the files and save them with a different file name each day, then delete the oldest one after, say, a week or so?

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Problem posting comment? Email me @