# rsync

rsync ist ein Tool, um Dateien zu kopieren.

<p class="callout info">zum Testen kann ein --dry-run am Ende des cmd angefügt werden</p>

```
rsync -aPh --info=progress2 --info=name0 --ignore-existing --log-file=/home/root/rsync.log "/mnt/START" "/mnt/ZIEL"
```

oder auch

```
rsync -aPhzv --delete --info=progress2 --bwlimit=2048 --log-file="/home/rsync_$(date +'%Y-%m-%d_%H-%M').log" --exclude data/pl-admin --exclude data/appdata_ockpw9aiwppb /mnt/praxis-volume-01/docker-data/volumes/nextcloud_db/_data/ /mnt/pl-hz-03/mnt/praxis-volume-03/docker-data/volumes/nextcloud_db/_data/
```

Eikes Empfehlung für **<span style="text-decoration: underline;">Spiegelung</span>**:

```
rsync -aPhv --info=progress2 --log-file="/home/rsync_$(date +'%Y-%m-%d_%H-%M').log" /mnt/volume-01/docker-data/volumes/ /mnt/volume-02/docker-data/volumes/
```

Eikes Empfehlung für **<span style="text-decoration: underline;">Kopiervorgang</span>** (vorhanden Dateien im Zielverzeichnis bleiben erhalten):

```
rsync -aPhv --info=progress2 --ignore-existing --log-file="/home/rsync_$(date +'%Y-%m-%d_%H-%M').log" /mnt/volume-01/docker-data/volumes/ /mnt/volume-02/docker-data/volumes/
```

<s>zwischen zwei SSH-Clients</s> ⚠ FALSCH, GEHT NICHT MIT ZWEI REMOTES, NIMM SCP STATTDESSEN (siehe scp Eintrag hier im Wiki)

```
rsync -aPhv --info=progress2 --ignore-existing --log-file="~/rsync_$(date +'%Y-%m-%d_%H-%M').log" -e ssh root@1.2.3.3:/pfad/zum/quellordner/ root@1.2.3.4:/pfad/zum/zielordner
```

Nextcloud Übertragung:

```
rsync -aPhv --info=progress2 --log-file="/home/rsync_$(date +'%Y-%m-%d_%H-%M').log" --exclude Joplin-Sync /mnt/fn-volume-01/docker-data/volumes/nextcloud_app/_data/data/Eike/files/ /mnt/fn-volume-02/docker-data/volumes/nextcloud_aio_nextcloud_data/_data/Eike/files/
```

Erklärung:

- `-a` → Archiv-Modus (rekursiv, Rechte, Zeit, Symlinks etc.)
- `-P` → Fortschritt je Datei &amp; abgebrochene Übertragungen fortsetzen
- `-h` → „Human readable“ Größenangaben (z.B. 4.3M)
- `-z` → Komprimiert Daten bei Übertragung
- `-v` → „Verbose“ Ausgabe (mehr Infos)
- `--bwlimit=2048` → Limitert die Übertragungsgeschwindigkeit auf zb 2048 Kilobyte/s (2 MB/s), gut für SSH oder tagsüber
- `--info=progress2` → Zeigt Gesamtfortschritt aller Dateien
- `--perms` → Überträgt die Datei-Berechtigungen (explizit, steckt aber schon in `-a`)
- `--times` → Überträgt die Änderungszeit (auch schon in `-a`)
- `--log-file="/home/rsync_$(date +'%Y-%m-%d_%H-%M').log"` → Schreibt ein Logfile
- ENTWEDER:
- `--delete` → Löscht im Ziel alles, was es in der Quelle nicht mehr gibt (gut für Spiegelung)
- ODER:
- `--ignore-existing` → Erhält Dateien im Zielordner, auch wenn die Dateien sich unterscheiden (schlecht für Spiegelung)
- ODER:
- --update → Überschreibt nur wenn Quelldatei neuer ist

[https://www.rsyncinator.app/web](https://www.rsyncinator.app/web)

[https://askubuntu.com/questions/609303/how-can-i-view-a-progress-bar-when-running-rsync](https://askubuntu.com/questions/609303/how-can-i-view-a-progress-bar-when-running-rsync)

### Log-Output lesen

Quelle: [https://stackoverflow.com/questions/4493525/what-does-f-mean-in-rsync-logs](https://stackoverflow.com/questions/4493525/what-does-f-mean-in-rsync-logs)

Explanation of each bit position and value in rsync's output:

```
YXcstpoguax  path/to/file
|||||||||||
||||||||||╰- x: The extended attribute information changed
|||||||||╰-- a: The ACL information changed
||||||||╰--- u: The u slot is reserved for future use
|||||||╰---- g: Group is different
||||||╰----- o: Owner is different
|||||╰------ p: Permission are different
||||╰------- t: Modification time is different
|||╰-------- s: Size is different
||╰--------- c: Different checksum (for regular files), or
||              changed value (for symlinks, devices, and special files)
|╰---------- the file type:
|            f: for a file,
|            d: for a directory,
|            L: for a symlink,
|            D: for a device,
|            S: for a special file (e.g. named sockets and fifos)
╰----------- the type of update being done::
             <: file is being transferred to the remote host (sent)
             >: file is being transferred to the local host (received)
             c: local change/creation for the item, such as:
                - the creation of a directory
                - the changing of a symlink,
                - etc.
             h: the item is a hard link to another item (requires 
                --hard-links).
             .: the item is not being updated (though it might have
                attributes that are being modified)
             *: means that the rest of the itemized-output area contains
                a message (e.g. "deleting")
```

Some example output from rsync for various scenarios:

```
>f+++++++++ some/dir/new-file.txt
.f....og..x some/dir/existing-file-with-changed-owner-and-group.txt
.f........x some/dir/existing-file-with-changed-unnamed-attribute.txt
>f...p....x some/dir/existing-file-with-changed-permissions.txt
>f..t..g..x some/dir/existing-file-with-changed-time-and-group.txt
>f.s......x some/dir/existing-file-with-changed-size.txt
>f.st.....x some/dir/existing-file-with-changed-size-and-time-stamp.txt 
cd+++++++++ some/dir/new-directory/
.d....og... some/dir/existing-directory-with-changed-owner-and-group/
.d..t...... some/dir/existing-directory-with-different-time-stamp/
```