Changes

Jump to navigation Jump to search
1,408 bytes added ,  21:53, 18 March 2020
m
Line 1: Line 1: −
== Create local backups ==
+
==Create local backups==
  rsync -av --delete /Origen/ /Destino/
+
  rsync -avzXAS --delete /Origen/ /Destino/
 +
Note: if origin ends with '/' it will copy the contents of the directory else it will copy the directory
 +
 
 
The code above will synchronize the contents of Directory1 to Directory2, and leave no differences between the two. <br />
 
The code above will synchronize the contents of Directory1 to Directory2, and leave no differences between the two. <br />
 
If rsync finds that Directory2 has a file that Directory1 does not, it will delete it. <br />
 
If rsync finds that Directory2 has a file that Directory1 does not, it will delete it. <br />
 
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 a file that has been changed, created, or deleted in Directory1, it will reflect those same changes to Directory2.
   −
#-a – The archive option = -rlptgoD
     −
##-r – (as mentioned above)
+
*-a – The archive option = -rlptgoD
    -l – copy symlinks as symlinks
+
**-r – (recursive into directories)
    -p – preserve permissions
+
**-l – copy symlinks as symlinks
    -t – preserve modification times
+
**-p – preserve permissions
    -g – preserve group
+
**-t – preserve modification times
    -o – preserve owner
+
**-g – preserve group
    -D – preserve device files and special files
+
**-o – preserve owner
 +
**-D – preserve device files and special files
 +
*-v – increase verbosity
 +
*-z – compress file data during the transfer
 +
*-X – preserve extended attributes
 +
*-A – preserve ACLs (implies -p option)
 +
*-S – handle sparse files efficiently
 +
*--delete – if the file is deleted from the source directory, delete it from the target directory
   −
-v – increase verbosity
+
==From your local machine==
-z – compress file data during the transfer
+
rsync -chavzP --stats user@remote.host:/path/to/copy /path/to/local/storage
-X – preserve extended attributes
  −
-A – preserve ACLs (implies -p option)
  −
-S – handle sparse files efficiently
  −
--delete – if the file is deleted from the source directory, delete it from the target directory
      +
*-c, --checksum              skip based on checksum, not mod-time & size
 +
*-h, --human-readable        output numbers in a human-readable format
   −
1. -a = 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.<br />
+
==From your local machine with a non standard ssh port==
2. -v = verbose. You can see exactly what rsync is backing up. backups.<br />
+
rsync -avz -e "ssh -p $portNumber" user@remote.host:/path/to/copy /local/path
3. –delete = This tells rsync to delete any files that are in Directory2 that aren’t in Directory1.<br />
     −
== Remote backups ==
+
==Or from the remote host==
 +
rsync -chavzP --stats /path/to/copy user@host.remoted.from:/path/to/local/storage
 +
 
 +
==Remote backups==
 
  rsync -av –delete -e ssh /Origen/ user@192.168.11.21:/Destino/
 
  rsync -av –delete -e ssh /Origen/ user@192.168.11.21:/Destino/
or with password and port settings:
+
 
 +
===With private key authentication===
 +
<syntaxhighlight lang="bash">
 +
rsync --progress -avz -e "ssh -i /home/rafa/.ssh/id_rsa" /home/rafa/git-master/ ubuntu@example.com:/home/ubuntu/git-master/
 +
 
 +
rsync --progress -avz -e "ssh -i /home/rafa/.ssh/RecoverAccess.pem" ubuntu@ec2-54-154-200-219.eu-west-1.compute.amazonaws.com:/mnt/backup/ nf-es/
 +
</syntaxhighlight>
 +
 
 +
==with password and port settings==
 
  rsync -av –delete -e 'ssh -p 12345' /Origen/ user@192.168.235.137:/Destino/
 
  rsync -av –delete -e 'ssh -p 12345' /Origen/ user@192.168.235.137:/Destino/
 +
 +
==Changing permissions and ownership==
 +
pgrep -f "rsync -avz --chown=turing:www-data --chmod=Du=rwx,Dgo=rx,Fu=rw,Fog=r --log-file=${LOG_FILE}" > /dev/null || rsync -avz --chown=tur$│
 +
==Remove source files after succesfull transfer==
 +
rsync --remove-source-files -azv /path/to/Download/*.avi laptop:~/Download
 +
<syntaxhighlight lang="bash">
 +
find . -regex  '.*\(avi\|mp4\|mkv\)$' -exec rsync --remove-source-files -azv {} morpheus.lan:/media/video/classification_pending/ \;
 +
</syntaxhighlight>
 +
 +
==Follow symlyncs (-L)==
 +
rsync -L /path/to/Download/*.avi ~/Download
 +
 +
==Exclude==
 +
rsync -avz --exclude 'dir1' source/ destination/
 +
rsync -avz --exclude 'dir*' source/ destination/
 +
 +
==Arguments with spaces==
 +
<syntaxhighlight lang="bash">
 +
rsync -avxP --protect-args "xe50582@jupyter.rra.lan:/home/xe50582/Notebooks/Rafael Herrero/Text Clustering/news/*" .
 +
</syntaxhighlight>

Navigation menu