| |
en:linux:backup:rsync [2023/10/24 21:19] – angelegt psycore | en:linux:backup:rsync [2023/11/07 16:20] (current) – Automatic translation 82.80.249.212 |
---|
====== Linux backup with rsync ====== | ====== Linux backup with rsync ====== |
| |
Linux backups can be done perfectly with rsync. Read here how it works. | Linux backups can be performed perfectly with rsync. Read here how it works. |
| |
===== Introduction ===== | ===== Introduction ===== |
| |
With "rsync" you can copy directory structures. The backup can then be compared with the original and if there are changes in the original, the backup is also updated. | With "rsync" you can copy directory structures. The backup can then be compared with the original and if changes are made to the original, the backup is also updated. |
| |
===== Procedure ===== | ===== Procedure ===== |
| |
If you create copies of the backup, you have various versions. | If you create copies of the backup, you will have various versions. |
| |
<code bash> | <code bash> |
creates a copy of <quelle> in <ziel>. After a 2nd call, only the changes are saved. | creates a copy of <quelle> in <ziel>. After a 2nd call, only the changes are saved. |
| |
To create a second version of the backup, you can create a hard link to the target directory: | To create a 2nd version of the backup, you can create a hard link to the target directory: |
| |
<code bash> | <code bash> |
===== Info ===== | ===== Info ===== |
| |
A hardlink is a reference to a file. A file can therefore have several names, i.e. be accessible under several names. Therefore, no copy of the binary data is created, but only another name is assigned. In our example, this has the advantage that only a "virtual" copy is made and the disk space is not further limited. The file would only be deleted if the last link to the file was also deleted. Therefore, one can also delete old backup folders without having to accept data loss in new versions. | A hard link is a reference to a file. A file can therefore have several names, i.e. it can be addressed under several names. This means that no copy of the binary data is created, only another name is assigned. In our example, this has the advantage that only a "virtual" copy is made and the disc space is not further restricted. The file would only be deleted when the last link to the file is deleted. It is therefore also possible to delete old backup folders without losing data in new versions. |
| |
Calling up our command again now compares the data in <ziel> with <quelle>. If there are changes, they will be changed in <ziel> will also be changed. The hardlinks in <backup_alt> remain unaffected. The data occurrence that requires real disk space are the changes. | Calling our command again now compares the data in <ziel> with <quelle>. If there are any changes, these are also changed in <ziel> will also be changed. The hard links in <backup_alt> remain unaffected. The data occurrence that requires real disc space are the changes. |
| |
Now there are two more things to consider in the simple version: | Now there are two more things to consider in the simple version: |
| |
* --delete --delete-excluded : Files that are no longer present in the source, e.g. due to deletion or moving, are also deleted in the target. | * --delete --delete-excluded : Files that no longer exist in the source, e.g. due to deletion or moving, are also deleted in the target |
| |
* --exclude-from=file : Here you can specify a file containing files and directories that are not to be synchronised. The individual entries are each in a line. You can use wildcards. | * --exclude-from=filei : Here you can specify a file containing files and directories that are not to be synchronised. The individual entries are each on one line. You can use wildcards. |
| |
===== Example of a backup process ===== | ===== Example of a backup process ===== |
This creates an archive in "/data1/backup/home_imap_MailDir", shows what rsync is currently doing, deletes files that are not present in the original if necessary. The path to the backup directory should already exist. | This creates an archive in "/data1/backup/home_imap_MailDir", shows what rsync is currently doing, deletes files that are not present in the original if necessary. The path to the backup directory should already exist. |
| |
Then copy the backup with a hard link to get an "old" version. Of course, this could also be done before the next backup, since the same version is present twice. | Then copy the backup with a hardlink to get an "old" version. Of course, this could also be done before the next backup, as the same version exists twice. |