You can check our other guides for more rsync examples or you can learn how to exclude files and directories with rsync.The use of hard drives for backups is outpacing other forms of backup media by a country mile. Take caution when using this tool and make sure you do a dry run if you are unsure about the rsync options you want to use. This tutorial showed you how to back up data using rsync both locally and over a network. You can also do this for local transfers if you want to have a backup on another drive or partition. Now, you have a zipped copy of your directory on a remote server. ![]() Then transfer that file to another location: rsync -avz /home/test/Documents/Dir1.zip :/home/test/backup In our case, we will zip Dir1 into Dir.zip: zip /home/test/Documents/Dir1.zip /home/test/Documents/Dir1 rsync -avz /home/test/Documents/Dir1 :/home/test/backupĪnother option is to use the zip command to zip your files or directory and then run rsync. To compress data during transfer, use the -z switch with your rsync command. You can use rsync’s built-in option to compress data, or you can use a different tool to do that before running rsync. ![]() To save some space, you can compress your data before transferring it to another location. When needed, you can delete the source files after you transfer them to another location. To specify port 4455, for example, run the above command in this format: rsync -av -e 'ssh -p 4455' /home/test/Documents/Dir1 :/home/test/backup If you need to specify a different port for the SSH connection, use the -eflag and enter SSH options. The example we used here assumes that SSH uses the default port. Set up SSH key-based authentication, and you will be able to use passwordless login to the remote machine. Note: You can evade entering a password every time you want to back up data with rsync over SSH. Use the full path for both the source and destination to avoid errors.įor example, to back up a Dir1 from Documents to /media/hdd2/rscync_backup, use the rsync command in this form: rsync -av /home/test/Documents/Dir1 /media/hdd2/rsync_backup The path can be any location – another partition, hard drive, external storage, etc. We will start by performing a backup of a directory on the same Linux machine. dry-run SOURCE DESTINATION Use Rsync to Back up Data Locally Use the basic syntax format and add -dry-run: rsync Accidental data loss can occur, but this option helps prevent it.įor simple transfers, you may not need to use -dry-run, but when a larger set of data is in question, we strongly advise that you do. Even worse, you may unintentionally overwrite or delete files.įor that reason, use the -dry-run option to confirm the tool does what you want to do. If you use a wrong option or a wrong destination, you may end up mixing your data. So, be careful when backing up your files. The rsync utility allows you to manipulate your data in different ways. There are many rsync options and examples, so use any of them you need for your use case. ![]() Additionally, since we will be backing up data in directories, we will use the archive mode -a for recursive syncing. Backing up Data with Rsyncįor a better understanding of what rsync does, we will use the verbose switch -v. In both cases, the source and destination are a directory or a file path. ![]() To transfer files to an external location, we will use a pattern that is a bit different: rsync The syntax for using the rsync tool is different for local and remote transfers.įor local backups, the syntax follows this basic pattern: rsync
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |