⬆️ ⬇️

backup rsync

If your computer doesn’t store your favorite photos or

documents, this note will not interest you. If you already make backups and you are completely satisfied with the mechanism of working with them, you should also skip this note. If you think you are good at linux, you are unlikely to get anything new in it. For the rest - share .



Why do I need to back up important data?



As Woland said in The Master and Margarita, it is not terrible that man is mortal, but that he is suddenly mortal. The same is true of hard drives. In my life, it seems, only 2 HDDs died, one died suddenly (very valuable data was lost), the other almost suddenly (it was possible to recover some data), the situation among my friends is not much different on average. Screw death statistics is much less subjective, from Google - on average, the screw lives for several years, and in 60% of cases the screws die suddenly, even for SMART



In addition to hardware, there are also software reasons for data loss - once the WIN95.CIH virus took down the first few megabytes of a disk, including FAT, which resulted in complete data unavailability. The month of fierce programming and lasagna with DiskEdit is gone, so that in the absence of the Internet you can deal with FAT structs and restore them. One day Patrition Magic hung on transferring a section. Once at work

Partition Magic turned off the electricity in the panel on the landing. In the last two cases, important data is not lost - but this is just luck. If you are connected to the network, then there is the likelihood of hacking and destruction of important data by an attacker. From this kind of damage RAID-array will not save.

')

How to evaluate the feasibility of backup?



There is such a thing as risk stiffness - this is the probability of risk occurring multiplied by the cost of risk in money. The cost of risk in this case is how much you would be willing to pay money to recover all the lost information. We estimate the probability of risk from below. I can only evaluate hardware failures, because I don’t have the rest of the statistics, and this reason for me already

was enough. The probability of a hard drive dying in 3 years is at least 24% in any case, regardless of whether it is new or not. The probability that death will be sudden, as I already wrote, is 60%. Total probability of sudden death in 3 years is 14%. If two HDDs are used without mirroring, the probability of death of at least one of them during this period is 26%.

Of course, you need to take into account the value of the data on these disks - I have 2 HDDs with valuable data (loss of any fatal) and one with music and movies - I will be upset about losing my favorite music collection, but I will survive.



Once I was a student and sometimes lived on 600 rubles a month, but now I can afford some investments in data security. Today I bought an external (USB) hard disk of 320 gigabytes, and this pleasure cost me 3,000 rubles. Why hard drive? Because I have a lot of data - only the pictures that are dear to my heart occupy 40 gigabytes of etac. And I don’t want to spend much time on it and I would like, without sorting everything that has accumulated over many years into “important - unimportant” except music and movies. Why external? Ability to store separately from the computer in case of theft (although this is more important for laptops), not connected to the computer (in case of errors, fatal to the data).



Security.



I am not paranoid, but the hard disk contains data, the security of which is needed not only by me - for example, it is not at all necessary to fall into the hands of extraneous photographs of familiar girls in the “nude” style. Accordingly, we encrypt the disk - I encrypted everything. In debian, everything is done out of the box in a few minutes and therefore I have no doubt that I can then easily recover this data, the main thing is to remember to write down the cascade of algorithms and password hint on paper and store it in a box with a screw. I would not recommend using third-party commercially grunty tools.



Getting started.



I, without hesitation, decided to backup all the unused (but those that are just in case it is better not to lose) the entire sections, for the test I took the section with the once installed WIN98:



# cp /dev/hda1 /mnt/backup/images/

we test:

# mkdir /mnt/hda1-backup-test

# mount /mnt/backup/images/hda1 /mnt/hda1-backup-test -o loop

# ls /mnt/hda1-backup-test/

boot.ini io.sys ntdetect.com ( )




Hooray! Works!



Since I have working data in ext2 and ext3 file systems, I would like to use the fact that the attributes of files in ext2 / ext3 can contain information about its backup. However, dumping is extremely discouraged on mounted file systems - www.rhd.ru/docs/manuals/enterprise/RHEL-4-Manual/admin-guide/s1-disaster-rhlspec.html , dump.sourceforge.net/isdumpdeprecated. html . There is a huge choice between common backup technologies - tar, cpio, backup-manager, bacula and so on, but for now I’ve settled on rsync + cp - because the result can be read transparently anywhere, without unpacking and reading all incremental archives.



$ sudo rsync --archive --one-file-system /etc /home /root --delete /mnt/backup/rsync/`date +%F--%H-%M`



Need to save some recent backups? Please use the fact that the --link parameter of cp creates a hard link to the file instead of copying it.



$ sudo rsync --archive --one-file-system /etc /home /root --delete /mnt/backup/rsync/latest/

$ sudo cp --archive --link /mnt/backup/rsync/latest/

/mnt/backup/rsync/`date +%F--%H-%M`




Checking:



$ ls /mnt/backup/rsync/

2008-04-03--04-29 2008-04-03--04-34 latest




Want to see differences with backup? "Emulate" copying the current state to the backup state.



$ sudo rsync --archive --dry-run --verbose --one-file-system /etc /home /root --delete /mnt/backup/rsync/latest/



Want to see the differences between backups? Similarly.



$ sudo rsync --archive --dry-run --verbose --delete

/mnt/backup/rsync/2008-04-03--04-41/

/mnt/backup/rsync/2008-04-03--04-29/




That's all.



Sources:

About encryption: aiz-linux.blogspot.com/2007/11/gnulinux.html

About screws: habrahabr.ru/blog/hardware/24009.html ,

mydebianblog.blogspot.com/2007/11/blog-post.html

About rsync and more: www.mikerubel.org/computers/rsync_snapshots



You can also see:

rsnapshot - also uses rsync and hard links, better suited for backing up to non-removable media or to a network: habrahabr.ru/blogs/linux/45912

Source: https://habr.com/ru/post/51419/



All Articles