Cart

/ Domain name

/ Your .CO.UK domain
for only £ 4.99**

Get started with your own domain names

Register now

/ Other

/ Latest news

Launch of new Big Storage platform

Read more
Need help?

    Sorry, we could not find any results for your search querry.

    Using Rsync in Linux

    With Rsync you can quickly and securely move data between two Linux servers, or directories within a single Linux server, while preserving permissions, timestamps and (optionally) ACLs and extended attributes. In this guide, we show how to use Rsync to transfer data from server A to server B. The steps apply to Ubuntu, Debian, AlmaLinux, Rocky Linux and CentOS Stream. We assume two servers with SSH access.

    • Start with a trial run using --dry-run to avoid accidentally overwriting or deleting data.
    • Mind the trailing slash: /source/ copies the contents of the directory; /source copies the directory itself.
    • --delete removes files on the destination side that do not (or no longer) exist at the source. Combine it with --dry-run first.
    • Check disk space on the destination and ensure the SSH port and firewall rules are correct.
    • Make a backup before migrations (e.g. via Weekly Backups).
     

     

    Installing Rsync

     

    In principle, Rsync is present on all modern operating systems. If Rsync is not installed on your server—for example because you removed it—install Rsync first as follows:

     

    Step 1

    Connect to your Linux server via SSH, the VPS console (VPS) or the OpenStack console (OpenStack instance).


     

    Step 2 

    Install Rsync as follows:

    Ubuntu / Debian

    First update your server, then install Rsync:

    sudo apt -y update && sudo apt -y update
    sudo apt -y install Rsync
     
     

    AlmaLinux 10 / Rocky Linux 10 / CentOS Stream 10

    First update your server, then install Rsync:

    sudo dnf -y update
    sudo dnf -y install Rsync
     
     

     

    Using Rsync

     

    An Rsync command uses the syntax Rsync, arguments, source (a local directory or a directory on a remote server/computer) and the destination. The destination can also be a local directory, or a remote server/computer: Rsync can also be used perfectly well to copy files within a single server or computer.

     

    Testing Rsync

     

    Connect to the source server and run a test to check Rsync is working. Replace:

    • /directory/ : The directory on the server you’re currently connected to.
    • user : A user account with permission to connect to the remote server and to edit the directory where you’ll place the data.
    • @doelserver : The hostname or IP address of the server you’re moving the data to. 
    • /targetdir/ : The directory on the remote server to which you want to move the data.
    Rsync -avhn /directory/ user@doelserver:/targetdir/

    With the -avhn argument you add the following options:

    • a : archive mode: recursive; preserves permissions/owners/timestamps
    • v : verbose
    • h : human readable
    • n : dry-run

    A handy feature of Rsync is that you can also reverse it: you can connect to the destination server (where the files need to be sent) and simply connect to the source server instead of the destination, i.e.:

    Rsync -avhn user@bronserver:/directory/ /targetdir/

     

    Copying data with Rsync

     

    After a dry-run test, perform the actual copy (a ‘push’: from source to destination):

    Rsync -avHhz --progress --delete /directory/ user@doelserver:/targetdir/

    Or reverse the process here too and fetch data from the destination server (a ‘pull’: on the destination server you pull the data from the source server):

    Rsync -avHhz --progress --delete user@bronserver:/directory/ /targetdir/

    Most of the option flags were covered during testing. Here we additionally include the following (optional) ones: 

    • H : Preserve hard links
    • z : Compression during transfer
    • --progress : Show file transfer progress 
    • --delete : Remove extra files on the destination side. Use --delete only if the destination structure must be exactly the same as the source.

     

    Using a custom SSH port and/or SSH key

     

    Rsync -aHvz -e "ssh -p 2222 -i ~/.ssh/id_ed25519" /data/ user@doelserver:/data/

    Replace 2222 with the desired SSH port number and/or ~/.ssh/id_ed25519 with the directory and file name of your SSH key. 


     

    Optional Rsync arguments

     

    Rsync supports more arguments than those already mentioned. Below are some useful options:

    • --partial : Resume large files after an interruption.
    • --inplace : Write directly to the destination file; useful for large deltas.
    • --bwlimit=50M : Limit the connection’s bandwidth. 
    • --timeout=60 : Timeout in seconds.
    • --include='subdirectoryA/' --include='subdirectoryB/' --exclude='*' : Synchronise only subdirectoryA and subdirectoryB in the source directory and skip all other directories, for example:
      rsync -aHvz --include='projectA/' --include='projectB/' --exclude='*' /data/ user@doelserver:/data
    • --exclude='*.tmp' --exclude='.cache/' : Exclude files and subdirectories respectively—in this case files with the .tmp extension and the .cache/ subdirectory (and its subdirectories).

     

     

    Common issues:

     

    • Incorrect path due to missing ‘/’: Use /data/ to copy only the contents; use /data to copy the directory itself.
    • ‘Permission denied’ on system files: Run Rsync with sudo and use -A -X if you use ACLs/xattrs.
    • Slow connection: add -z (compression) or limit bandwidth with --bwlimit so other services remain responsive.
    • Need to resume after an interruption: use --partial or run the command again; Rsync transfers only the differences.

     

    That brings us to the end of our Rsync guide. With Rsync you can migrate data quickly and reliably between Linux servers, or within a single Linux server. Start with a dry-run, pay attention to the path (with or without a trailing slash), and use the right options for your situation (permissions, excludes, bandwidth, automation). Once verified, you can use --delete to make destination and source exactly the same.

    Was this article helpful?


    Provide feedback about this article

    Need help?

    Receive personal support from our supporters

    Contact us