frankyonnetti
2/1/2020 - 8:18 PM

#rsync

rsync #rsync

# rsync basic
rsync -a /tmp/foo/* /tmp/bar

# NOTE: the difference between including a forward slash (/) at the end of the source path, and omitting it.
foo/ # will transfer all files INSIDE the specified directory
foo  # will transfer the directory itself with all files inside


# rsync file count
rsyn -avz file/path/ file/path/ | wc -l


# rsync files down from server
# NOTE: by default, rsync only copies new or changed files from a source to destination.
rsync -auv --delete --exclude=site_files deploy@h8.designhammer.com:/var/www/devhammer.com/prod/www/dh/ /Users/frankyonnetti/Desktop/testdir

# alternative way to --exclude multiple files/dir is to list the files and directories in curly braces {} separated by a comma:
rsync -a --exclude={'file1.txt','dir1/*','dir2'} src_directory/ dst_directory/


# flags

-a # Archive
# The -a (–archive) flag is an alias to a collection of other flags, -rltpgoD

-r # Recursive
-l # Transfer any symlinks encountered
-t # Preserve time stamps
-p # Preserve permissions
-g # Preserve groups
-o # Preserve ownership
-D # Preserve block and character devices

# other
-h # Human-readable format of file sizes
-z # Compress
-v # Verbose
-n # Dry run
-u # allows rsync to skip files that are newer in the destination directory
--delete # removes files and data from the destination directory.