RSync

RSync copies files and can sync between servers

Backing up

RSync copies files and can sync between servers

Use RSync in [[Cronjob]]
Archive Backups with [[tar]]

TEST WITH: `--dry-run`

rsync -aAXv --delete --exclude={/home/danicus/.cache/*} /home /mounted/backup

    a= archive= its a few other tags as well
    A= keeps permissions
    X= keeps the next level of permissions
    v= verbose
    -- delete= deletes any files inside the file this will be copying to
    --exclude= excludes `file/this/*, andfile/that/*`
    /home= location of files you want to back up
    /mounted= the backup drive location
    see [[RSync#*NOTE "/"*]]

#### Multiple directories to one end location
###### use seperate command lines and run them seperately. 

sudo rsync -aAXv --delete /etc /mounted/backup/wallserver/
sudo rsync -aAXv --delete /home /mounted/backup/wallserver/
sudo rsync -aAXv --delete /root /mounted/backup/wallserver/
sudo rsync -aAXv --delete /var /mounted/backup/wallserver/
sudo rsync -aAXv --delete /usr/local/bin /mounted/backup/wallserver/
sudo rsync -aAXv --delete /usr/local/sbin /mounted/backup/wallserver/
sudo rsync -aAXv --delete /srv /mounted/backup/wallserver/
sudo rsync -aAXv --delete /opt /mounted/backup/wallserver/
sudo rsync -aAXv --delete /mounted/main /mounted/backup/wallserver/
#### Multiple directories to one end location FROM an Remote Source
rsync -e ssh root@remote.com:/path/to/file :/path/to/second/file/ /local/directory/


>#### Permissions denied (this my not work)
If you are denied because of `PermitRootLogin no`, create a new user
>
>Make a new user for rsync to use then add that name to the /etc/sudoers >file so that, that user can execute the rsync command without a >password
>In the /etc/sudoers file add:
>`rsyncuser ALL= NOPASSWD:/usr/bin/rsync`
>
>Then, we use _**rsync-path**_ to make _rsync_ works with the sudo.
>`--rsync-path="sudo rsync"`
>`rsync -aAXv --rsync-path="sudo rsync" --delete`

How to restore backup with RSync

https://askubuntu.com/questions/1011136/how-to-restore-backup-with-rsync

asically just revierse the order for the backup. 
-tag it rsync -aAXv
Then start from backup directory and end with destination directory

sudo rsync -aAXv --delete /mounted/backups/cpbackups/ /mounted/main/directory/location/

+from Backtup= /mounted/backups/cpbackups  
+To Destination= /mounted/main/directory/location?

*NOTE "/"*
The "/" means something!
At the end of the directory, if you do not include the "/" Rsync will make a directory inside the directory you specify, then will include the files in from there.
If you DO include the "/", it will drop the files/directories in, directly at the directory that you specify.

Example:

sudo rsync -aAXv --delete

 
((1)) /mounted/backups/cpbackups
((2)) /mounted/main/directory/location?

Without "/"
((1)) File name will be "cpbackups" and will make a directory named "cpbackups" and put it in ((2)). 

With "/"
Will take files from INSIDE ((1)) and put them INSIDE the ((2)) directory. 

**Change the flags**

rsync -aHAXvP /home_folder_path /backup_folder_path