How to use Rsync to sync files and directories at Hostinger

Learn how to use the Rsync utility to synchronize local and remote directories, create mirrors, and manage data transfers for your Hostinger services.

Updated 2 weeks ago

Rsync (Remote Sync) is a command-line tool used to synchronize files and directories between two locations. It is highly efficient because it only sends the parts of files that have changed. This guide explains the default command logic and provides common examples for managing your Hostinger VPS or managed hosting files.

Pre-requisites

  • SSH access enabled on your source and destination.
  • A Hostinger hosting plan that supports SSH (available on all plans except Single Web hosting plan).
  • A terminal or command-line interface.

The default Rsync command structure

Every Rsync command follows a standard syntax. Understanding this “formula” allows you to customize the transfer to fit your needs:

rsync [options] -e "ssh -p port" [source] [destination]

  • [options]: These define the behavior (e.g., -avz for archive, verbose, and compression).

  • -e "ssh -p port": This specifies the connection method and the SSH port. The correct port depends on your hosting type:

    • Shared/Cloud hosting: Hostinger uses port 65002 by default. You can confirm this on your hPanel under Advanced → SSH Access.
    • VPS hosting: The default port is 22, unless you’ve changed it.

    All examples in this guide use -p 65002. If you’re on VPS with the default port, replace this with -p 22.

  • [source]: The location of the files you want to move.

  • [destination]: Your server credentials and the path where you want the files to go.

TIP: Always test your command by adding -n or --dry-run to the options. This simulates the transfer without making actual changes.

Understanding the “Trailing Slash” ( / )

The presence of a slash at the end of the source path changes how the files are placed at the destination.

Option A: With a slash (source/)

This tells Rsync to copy only the contents of the folder. Use this when you want to move files directly into an existing directory on the server.

  • Default format: rsync [options] /local-folder/ user@ip:/remote-folder/

  • Example: rsync -avz ~/Desktop/my-files/ user@ip:/public_html/

  • Result: The files inside my-files will appear directly inside public_html.

Option B: Without a slash (source)

This tells Rsync to copy the entire folder itself. Use this when you want to recreate the folder structure at the destination.

  • Default format: rsync [options] /local-folder user@ip:/remote-folder/

  • Example: rsync -avz ~/Desktop/my-files user@ip:/public_html/

  • Result: You will see a new folder named my-files inside your public_html directory (/public_html/my-files/).

Common sync scenarios

Once you understand the default structure, you can apply it to these common Hostinger workflows.

1. Uploading files to Hostinger (Push)

To move a folder from your local computer to the server, use your local path as the source.

Default format: rsync [options] -e "ssh -p port" /local/path/ username@ip_address:/remote/path/

Example: rsync -avz -e "ssh -p 65002" ~/Desktop/website/ u123456789@1.2.3.4:/home/u123456789/domains/domain.com/public_html/

2. Downloading files from Hostinger (Pull)

To bring files from the server down to your computer, reverse the source and destination.

Default format: rsync [options] -e "ssh -p port" username@ip_address:/remote/path/ /local/path/

Example: rsync -avz -e "ssh -p 65002" u123456789@1.2.3.4:/home/u123456789/domains/domain.com/public_html/backup/ ~/Downloads/

3. Creating an exact mirror

To ensure the destination looks exactly like the source (deleting files at the destination that no longer exist at the source), add the --delete flag.

Default format: rsync [options] --delete -e "ssh -p port" [source] [destination]

Example: rsync -avz --delete -e "ssh -p 65002" ~/Desktop/website/ u123456789@1.2.3.4:/home/u123456789/domains/domain.com/public_html/

Optional: Synchronizing databases

If you are syncing a website with a database, files alone are not enough. You must export the database into a file so Rsync can “see” it and move it.

  1. On the source: Create a backup file: mysqldump -u db_user -p db_name > data.sql

  2. Sync: Run your Rsync command. If the data.sql file is inside your website folder, it will be moved automatically. Example: rsync -avz -e "ssh -p 22" ~/Desktop/website/data.sql u123456789@1.2.3.4:/home/u123456789/domains/domain.com/public_html/

  3. On the destination: Import the data into your new database: mysql -u db_user -p db_name < data.sql

By following the default Rsync structure, you can precisely control how data moves between your environments. Always verify your SSH port in hPanel and perform a dry run before executing a full synchronization.

NOTES

  • SSH Port: Hostinger shared and cloud hosting uses port 65002 by default. VPS hosting uses port 22 by default. Always verify your port in hPanel under Advanced → SSH Access before running commands.
  • Progress: Add the -P flag to see a progress bar for large transfers.
  • Unavailable on Single plans: Rsync requires SSH, which is not available on Single web hosting plans.