rsync
Copy file from local server to remote server
You need to have sudo with NOPASSWD
on server like so youruser ALL=(ALL) NOPASSWD: ALL
/usr/bin/rsync --delay-updates -F --compress --copy-links --archive --rsh='/usr/bin/ssh -S none -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' --rsync-path='sudo -u root rsync' --chown=postgres:postgres --partial /tmp/dump.sql remote.server.address:/tmp/
This also changes user and group on the target
Delete files on source after transfer
You need to pass the --remove-source-files
option to the rsync command. It tells rsync to remove from the sending side the files (meaning non-directories) that are a part of the transfer and have been successfully duplicated on the receiving side.
Do not pass the --delete
option to rsync command as it delete extraneous files from destination directory. Delete source after successful transfer using rsync.
Cинхронизировать /tmp с /home удаляя пустые папки
rsync -rogpav --delete /home /tmp
Синхронизировать локальную директорию с удалённой директорией через ssh-туннель со сжатием
rsync -az -e ssh --delete ip_addr:/home/public /home/local
Перенести директорию со всем содержимым и переименовать
rsync -av /var/lib/docker /data/disk2
mv /var/lib/docker /var/lib/docker.08-04-22.backup