
It gets slightly more complex when using it to sync data with an external host over the Internet, but we will show you a simple, fast, and secure way to do that. As you can tell, rsync is very easy to use. That about covers it as far as local backups are concerned.
#Rsync folder backup full
We will go over a few more handy switches towards the end of this tutorial, but just remember that to see a full listing you can type “man rsync” and view a complete list of switches to use. Noob tip: Notice the trailing slashes at the end of the directories in my rsync command – those are necessary, be sure to remember them. The screenshot above tells us that File1.txt and File2.jpg were detected as either being new or otherwise changed from the copies existent in Directory2, and so they were backed up. Note that without the verbose switch, you wouldn’t receive such detailed information. Using the script above, here’s the output generated by using rsync to backup Directory1 to Directory2. If you choose to use this option, I recommend also using the verbose options, for reasons mentioned above. –delete = This tells rsync to delete any files that are in Directory2 that aren’t in Directory1. Think about this: What if your hard drive is going bad, and starts deleting files without your knowledge, then you run your rsync script and it pushes those changes to your backups, thereby deleting all instances of a file that you did not want to get rid of?ģ. The reason I think verbose is important is so you can see exactly what rsync is backing up. a = recursive (recurse into directories), links (copy symlinks as symlinks), perms (preserve permissions), times (preserve modification times), group (preserve group), owner (preserve owner), preserve device files, and preserve special files.Ģ.
#Rsync folder backup code
Here is what the aforementioned code tells rsync to do with the backups:ġ.

There are a lot of different switches that you can use for rsync to personalize it to your specific needs. If rsync finds a file that has been changed, created, or deleted in Directory1, it will reflect those same changes to Directory2.

If rsync finds that Directory2 has a file that Directory1 does not, it will delete it.
#Rsync folder backup Pc
That's it, your local PC will now be able to authenticate with your remote server.The code above will synchronize the contents of Directory1 to Directory2, and leave no differences between the two.

In the second last command, replace the text between the quotation marks with that long public SSH key line. > $HOME/.ssh/authorized_keys chmod 0644 $HOME/.ssh/authorized_keys Copy it to your clipboard, and within your remote server run these commands: sudo su rsync mkdir -m 0700 $HOME/.ssh echo "ssh-rsa AAAAB. ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDNhyYKsjcGGdXmzOM3742+c+TzMLFdZtrMPj1q6JWNWzgY/gTGVy1C72kw6BcTYSG8B8kLQlaBRl16m2Gm8Ra/U1wl0TYSufOnRKjGq2glnBPysWNzR6i9qd4h/byKa4ptNH/ieYkT+BnSJVo8fT0iboYwEaL9D0jPtYxFzZes2ctsGZ/zi78VlX9N224YBtoZcrxK6gzKtcIVrplsXt4MbMCPc0hfr9f2VMt0HignLphTDLQWKwF3sGi4OHDPzNTRkjyHazsIOFIKDLQgdsIJv7b2VMs028YDqPnXHZZl4Ix5vg8ssqE+s/J+rzS0B6gwj2b/f6vJMI9DmTk8SO5LKWtSl4lXjLpQ1eP+xjf3SeMFWWkk2tPpGBo6d+8VJT6htj9Ga927qx3bYJ3FDdqjoE/28yBzMsg3wKI8lobiQGIbF0B0jZmSeq42ds7dh76iU/LOraWJWJhKPIjCYHdaVqj5rgxSulUW6oqr/LOxMNwsj5NLpyKygr5/RVjCUpxQLw5G7AClmW5nOZDFUgtI1CAOzhG8oYQes7jE7ZbQKmMf9IGquNV1BCRGX2mbcYad77UE2IjzPqSG8pFGb7ekZA6ukUk61fqoheL4Zl2jmhhWoXQ09LZE9FNfr1UwIoZ+GwUcip8NPIZPSo+Z4yMB/5VNF7J0o76eTNwh0gZlEw= long line is the public SSH key. Open the /~.ssh/ file in a text editor and you will see one large line that looks something like. To allow your local PC to authenticate, the public SSH key that was generated in the previous section needs to be copied over to the remote server.
