Supply password to rsync
Via environment variable
Use environment variable
RSYNC_PASSWORD to provide password to rsync command
rsync -zvr source destination
env RSYNC_PASSWORD=$PASSWORD rsync -zvr source destination
Via password file
rsync --password-file=rsync_pass -zvr source destination
Some other methods
sshpass and public key.
How can I rsync without prompt for password, without using public key authentication?
Rsync backup client
Rsync backup command can be used as below.
rsync -avR --delete
--backup-dir=/folder-`date +%Y.%m.%d` \
The password_file only contains rsync password without any other data.
rsync@server::NetBackup/folder, rsync is user id, server is rsync server, NetBackup is rsync service (share folder), folder is where backup to be saved.
The backup-dir is the folder created in the rsync server to save changes.
Configure rsync in TrueNAS
Create a user called rsync, with group rsync.
Create a dataset, owned by rsync:rsync, with permission 770.
Enable rsync service
Go to System Settings -> Services, enable rsync.
Click on Configure (Edit icon), select Rsync Module tab, key in following info, and save configuration.
- Module Name
- Access Mode: Read & Write
- User: rsync
- Group: rsync
Run following command from remote server
rsync -avR --password-file=/root/.rsync/password \
rsync a directory to a new directory with different name
A trailing slash on the source avoids creating an additional directory level at the destination.
rsync -a src/ dest
You can think of a trailing / on a source as meaning "copy the contents of this directory" as opposed to "copy the directory by name".
rsync -a -P src dest
rsync -a --progress src dest
Issue with rsync duplicate filesystem
Some issues encountered when using rsync to duplicate filesystem.
When duplicating the files, rsync didn't take care of extended attributes, users might lose rights on some files.
Sparse files (Untested)
In order to create/update sparse files, to steps required.
To create new files in sparse mode
rsync --ignore-existing --sparse ...
To update all existing files (including the previously created sparse ones) inplace.
rsync --inplace ...