How to backup a directory in Linux

I need to backup a directory named /var/www/html/ in Centos Linux version 7. I need to backup folder to /dev/sdb1 mounted at /disk2/ and USB pen mounted /mnt/external_usb_pen. What is the best way to backup a directory or folder in Linux?

You can use any one of the following tool:

  1. rsync
  2. tar
  3. pax and more

Use rsync command to backup a folder in Linux

Backup /var/www/html/ to /disk2/

rsync -avr /var/www/html/ /disk2/
rsync -avr /var/www/html/  /mnt/external_usb_pen/

You can backup to remote server as well:

rsync -avr /var/www/html/ user@server-name:/path/to/backup/dir/here/

See:
https://www.cyberciti.biz/tips/linux-use-rsync-transfer-mirror-files-directories.html\
And:
https://www.cyberciti.biz/faq/use-rsync-to-backup-directory/

Use tar to backup a directory in Linux

tar -zcvf /disk2/backup.tar.gz /var/www/html/

See the following for more info:
https://www.cyberciti.biz/faq/tar-compress-command-on-linux-unix-to-create-tarball/