How To Backup Linux File System?
Linux is stable operating system. There is rare strong operating system foundation. But critical errors have occurs rarely too. Or they me be some hardware related problems. If your Linux system got down where your database resides what will happen? If you have backup is not so big problem. We can simple recover from backup. What if we have no backup?
Backup Partition With dd
dd is 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 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 backup our boot loader sectors easily with dd. As we know dd work in raw mode so it only knows sectors and segments and Master Boot Records resides in 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 byte will be read at once
- count=1 specifies how many time will the read operation done
bs and count parameter we want to read 512 byte for one time
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.
- 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.