Rsync: Preserve / Copy Hard Links ( Backup Rsnapshot Directory Tree )

Posted on in Categories , , , , , , , last updated September 8, 2015

I‘m using rsnapshot filesystem snapshot utility to make incremental snapshots of local and remote filesystems for 10 production servers running on RHEL 5.x system. The rsnapshot commands makes extensive use of hard links, so if the file doesn’t change, the next snapshot is simply a hard link to the exact same file. How do I use the rsync command to copy my the entire snapshot directory /raid6/rsnapshot/ (around 4TB) to a remote server for mirroring purpose?

How To Use rsync Command To Backup Directory Under Linux

Posted on in Categories , , , , , , , last updated April 2, 2008

Q. How do I use rsync command to back up a home directory under Linux operating system?

A. rsync command easily backup your home directory to local secondary hard disk or remote server using ssh protocol. rsync is a software application for Unix systems which synchronizes files and directories from one location to another while minimizing data transfer using delta encoding when appropriate.

Task: Backup /home/tom to /mnt/usbpen

Assuming that USB pen or external USB hard disk is mounted at /mnt/usbpen, enter the following command to backup (sync) new files and changes to existing files but don’t remove files in backup directory:
$ rsync -au /home/tom /mnt/usbpen
To delete files in backup directory that no longer exist in directory being backed up, enter:
$ rsync -au --delete /home/tom /mnt/usbpen

See our previous article about using rsync for transferring files under Linux or UNIX from local or remote network computer.

Linux Copy One Hard Disk to Another Using dd Command

Posted on in Categories , , , , , , , , , , , , , last updated February 5, 2008

Q. How can I copy one hard disk to another using dd command?

A. dd command can copy disk in raw format. It will copy partition table and bootloader and all partitions within this disk. For example, you can copy /dev/sda to /dev/sdb (same size) using the following dd command. dd should complete with no errors, but output the number of records read and written.

Login as the root user (use sudo or su command)

WARNING! These examples may result into data loss, ensure there are good backups before doing this, as using dd wrong way can be dangerous.

Open terminal or shell prompt and type the following dd command:
# dd if=/dev/sda of=/dev/sdb

  • if=/dev/sda : Input disk (source)
  • of=/dev/sdb : Output disk (destination)

You can also copy hard disk or partition image to another system using a network and netcat (nc) command.

How to backup the remote files in Linux / UNIX

Posted on in Categories , , , , , , , , , , , , last updated August 24, 2007

Q. How do I make remote backups under Linux? I’ve CentOS 5 Linux server located in remote data center and I’d like to backup it to local or another server?

A. Both Linux / UNIX come with handy tools to make secure remote backups. You can use tool called rsync for automating remote backups of your Linux, UNIX, Windows server, Mac OS X and BSD systems. rsync is a program with many more options and uses the rsync remote-update protocol to greatly speed up file transfers when the destination file is being updated.

Task: Copy files / backup files from remote Linux server

Let us say you would like to backup files from remote server called and directory called /home/vivek to local directory called /backup, type the command as follows on local system:
$ rsync -avz -e ssh [email protected]:/home/vivek/ /backup
You need to supply password for vivek user.

Task: Exclude files from backup

You can also skip few files from backup. Let us say you don’t want to backup all C source code file, enter:
$ rsync --exclude '*.cpp' -avz -e ssh [email protected]:/home/vivek/ /backup

Task: Automatic backup using a shell script

SSH always prompts for a password. To automate process via a shell script you need to remove password using SSH key i.e. generate passphraseless keys, enter (type at local system):
$ ssh-keygen -t dsa
When asked for to enter passphrase, just press [ENTER] key twice. Now copy public key to remote server:
$ scp ~/.ssh/ [email protected]:.ssh/authorized_keys
Now you can login without a password. For more information see – howto setup SSH with DSA public key authentication and RSA key authentication for password less login.

Now create a simple shell script as follows:
$ vi
Append code:
rsync --exclude '*.cpp' --exclude '*.log' -avz -e ssh [email protected]:/home/vivek/ /backup

Setup executable permission using chmod command:
$ chmod +x
Use cron to command to backup remote server:
$ crontab -e
Make a backup everyday:
@daily /path/to/
Save and close the file.

Howto: Backup CentOS / Fedora Linux / Red Hat Enterprise Linux server system

Posted on in Categories , last updated July 26, 2007

Q. How do I backup files and database for the Red Hat Enterprise Linux / CentOS Linux? Currently I’ve MySQL server running on CentOS 5 and Web server and file server using RHEL 5. How do I backup all these servers?

A. Regular backup is an essential for Linux system. You can take backup on
=> Tape
=> NAS Server
=> DVD
=> Network server etc

Implementing a backup policy that includes rotating backup media and keeping copies of backup media offsite is the most reliable way of minimizing damage. See following resources on our site for more information including commands and shell scripts:

  1. Perform backups for the Linux operating system
  2. How to backup MySQL databases, web server files to a FTP server automatically
  3. Howto Backup PostgreSQL Databases
  4. All backup shell scripts