How To Backup Linux File System? – POFTUT

How To Backup Linux File System?

Linux is a stable operating system. There is a rare strong operating system foundation. But critical errors have occurs rarely too. Or they may be some hardware-related problems. If your Linux system got down where your database resides what will happen? If you have a backup is not so big problem. We can simply recover from a backup. What if we have no backup?

Backup Partition With dd

dd is a very useful tool. It is simple operation is convert and copy but this function can be used for different purposes like back up.

$ sudo dd if=/dev/vda1 of=/mnt/backup.dd
  • dd operation requires root privileges so we use sudo
  • if=/dev/vda1 is input file where vda disk first partition
  • of=/mnt/backup.dd  is out output file where we create a new file named backup.dd

This operation will take some time because the whole partition will be backed up.

Backup Boot Loader (MBR) with dd

We can back up our boot loader sectors easily with dd. As we know dd work in the raw mode so it only knows sectors and segments and Master Boot Records resides in the first 512 byte we can use dd. This backup can be useful if we will install Windows or other operating-system other partitions and do not want to lose our MBR

$ dd if=/dev/sda of=/mnt/mbr.bak bs=512 count=1
  • if=/dev/sda is disk where MBR resides
  • of=/mnt/mbr.bak is our backup file
  • bs=512 provides how many bytes will be read at once
  • count=1 specifies how many time will the read operation is done

With bs and count parameter we want to read 512 bytes for one time

LEARN MORE  Linux dd Command To Backup with Examples

We can recover our backup like below

$ dd if=/mnt/mbr.bak of=/dev/vda bs=512 count=1

As you see we have changed the input and output files.

Some Tips

  • To continue even copy operation has error we can provide conf=noerror parameter.
  • To sync without buffering data with dd sync operation can be used.

Leave a Comment