[Linux](EN) Copy files to local or remote using rsync

Let’s use rsync command in Linux base OS.


Environment and Prerequisite

  • Linux
  • Bash shell(/bin/bash)


rsync command

Basic

  • rsync : It represents Remote Sync. It is a fast, versatile, remote (and local) file-copying tool which can use with various options
  • It is similar file-copying tool like rcp and scp. It can copy file and directory to not only remote but also local.
  • There are so many options that can be combined for many functions.(preserve symlink, preserve permission, preserve timestamp etc)


Basic Usage

  • Contents from manual page
rsync [options ...] [source] [target]

옵션

  • -v : Increase verbosity. It give more information about copying process.
  • -z : Compress files when copying
  • -h : Print human-readable mode
  • -a (same as -rlptgoD) : Archive mode. It is same as -rlptgoD options. Those options explanation are at below of this option. It copies symlink, permission, timestamp and etc properties.
  • -r : Recurse into directories. Use if for directory copy
  • -l : Copy symlinks as symlinks
  • -p : Preserve permissions
  • -t : Preserve modification times
  • -g : Preserve group
  • -o : Preserve owner(super-user only)
  • -D (same as --devices --specials) : Same as --devices --specials)
  • --devices : This option causes rsync to transfer character and block device files to the remote system to recreate these devices.(root only)
  • --specials : This option causes rsync to transfer special files such as named sockets and fifos.


Examples

  • Local file
# rsync [File Name] [Target Path]

rsync -avzh test_file.txt /tmp
  • Local directory
# rsync [Directory Name] [Target Path]

rsync -avzh test_directory /tmp


# Copy all files in directory
# rsync [Directory Name]/ [Target Path]

rsync -avzh test_directory/ /tmp
  • Remote file
# rsync [File Name] [User]@[IP Address]:[Path]

rsync -avzh test.txt twpower-private-server:~
rsync -avzh test.txt twpower@192.168.1.2:~
  • Remote directory
# rsync [Directory Name] [User]@[IP Address]:[Path]

rsync -avzh test.txt twpower-private-server:~
rsync -avzh test.txt twpower@192.168.1.2:~


# Copy all files in directory
# rsync [Directory Name]/ [User]@[IP Address]:[Path]

rsync -avzh test_directory/ twpower-private-server:~
rsync -avzh test_directory/ twpower@192.168.1.2:~


Reference

[Linux] 쉘 스크립트에서 멀티프로세스(혹은 스레드) 기능 사용하기

> 백그라운드로 명령어를 실행해서 병렬적으로 실행되는 멀티 프로세스 환경을 만들어보자.## 환경- Linux 기반 시스템- Bash shell(/bin/bash)## 멀티프로세스? 병렬처리? 멀티스레드? 백그라운드 프로세스?- 여기서 진행할 방식...… Continue reading