Dojo Wudan
posts   tags   about  

Rsync: upload and sync files

rsync is a simple tool to copy files or folders to your server from local, or sync files from your server to your local. You may use filezilla or similar ftp manager, but with a simple code you can do it all easily. And assuming you are using SSH key to login to your server, with a simple bash script, you can do it easier than ever.

Install rsync

on server: apt install rsync (as it is debian)

on local: pacman -S rsync (as it is arch)

Now lets upload our files from your local machine run:

rsync -rtvzP /path/to/file/ root@example.org:/path/on/the/server

Now it will upload the files inside of the file folder to server folder. If you omit the / after file, then it will upload file folder to the server folder, so you need to check couple of times about this.

If you omit root@, then it will try to login as your local username. So be careful about that

Lets talk about the options:

  • -r: include subfolders
  • -t: transfer modification times, so you wont be uploading everything all time, only changed ones
  • -v: visual, show files uploaded
  • -z: compress files to upload
  • -P: if the upload breaks, it will continute where it is left off.

Script

Writing the above code might be too much all the time, so lets create a nice bash script.

vim sync.sh

1
2
3
4
5
#!/bin/bash

rsync -rtvzP /path/to/file/ root@example.org:/path/on/the/server

echo "Upload done master! LFG"

chmod +x sync.sh

now in this folder, whenever you write sh sync it will do whatever needed, and greet you with LFG!.

Last note about downloading files from the server:

rsync -rtvzP root@example.org:/path/to/file /path/to/file

Just reverse the file order.


🌊⛰🔥