]> www.wagner.pp.ru Git - oss/restore.git/blob - README.md
Documented backup and afermount scripts
[oss/restore.git] / README.md
1 Restoration script for full linux backup
2 ========================================
3
4 Prepare for backups
5 -------------------
6
7 Before you'll be able to restore your system from backup, you have to do
8 backups.
9
10 1. Get an USB thumb drive or external HDD big enough to hold entire
11    content of our notebook's SSD.
12 2. Install [gparted-live](https://gparted.org/livecd.php) into beginning of this disk
13 3. Format rest of this disk (gparted would take no more than half of GB
14 at the beginning) as ext4 system
15 4. Install [rsnapshot](https://rsnapshot.org/) on your machine and set up it to make backup into
16    ```
17    /media/${your name}/${label of your USB partition}/${hostname}
18    ```
19    Or whereever your desktop enviroment mountes removable disks.
20
21    If you have big usb HDD and several notebooks, you can backup all of
22    them on one medium.
23    You should backup everything including /boot/efi, although you can
24    omit mozilla cache and other thinks which are likely to change during
25    backup.
26
27 5. Do first backup. Do:
28    ```
29    echo p |fdisk /dev/nvme0n1 > partitions.layout  
30    ```
31
32    copy restore script into root of your backup partition.
33
34 Do backup regularly
35 -------------------
36
37 Don't forget to insert this USB drive into your notebook and run 
38 `rsnapshot` with appropriate argument as root on regular basis.
39
40 Use alpha/beta/gamma modes of `rsnapshot`, so you'll store daily backups
41 for last week, weekly ones for last month and several monthly ones.
42
43 Since backup to external drive requires human intervention anyway (pick
44 drive from drawer and plug it into computer, and then return back), I
45 don't expect myself to do backups every day. Why should I backup a
46 notebook I haven't switched on since last backup?
47
48 This set of scripts includes some scripts which simplify semiregular
49 backups on removable drive. 
50
51 1. **backup** - perl script which checks if there are enough backups on
52 level alpha done and it's time to do next level beta backup.
53 It reads `/etc/rsnapshot.conf` for `snapshot_root` and `retain`
54 parameters. After successful backup it unmounts backup drive.
55
56 2. **aftermount** - this script inteneded to be run by automounting
57 system in your desktop session (tested with spacewm). It runs after
58 removable disk is mounted and checks if this disk contains
59 `snapshot_root`. If so, it displays dialog window asking you if you want
60 to run backup. If yes, it starts **backup** using sudo.
61
62 3. **backup.sudo** - place this file into `/etc/sudoers.d` so
63 **aftermount** would be able to run **backup** as root without password.
64
65
66 Restore old files occasionaly
67 -----------------------------
68
69 Sometimes you'll find out that you have incedently removed or modified
70 some file. You can than plug your backup drive in and get yesterday's or
71 week ago copy.
72
73 That is why **aftermount** script displays dialog requiring you to
74 confirm start of backup. You may want to plug backup drive in just to
75 dig out some files.
76
77 When disaster happens
78 ---------------------
79
80 When your SSD drive dies, or have been irrepairable  wiped out,
81 or hit by trojan or cryptolocker so it is easier to wipe out then do 
82 anything else:
83
84 1. Repair the hardware
85 2. Insert your backup drive in USB port and boot from it. Mount your
86    second partition under, say `/mnt`
87 3. From parted-live GUI create necessary partitions. You can consult
88    partitions.layout file which you have created while preparing backup.
89    Don't forget create vfat partition for `/boot/efi`, if you are using UEFI
90    boot.
91 4. Mount newly created root partition under, say `/target`
92    and if you use separate partitions for `/home`, `/var` or anything else,
93    mount them on `/target/home`, `/target/var` etc.
94    Don't forget to mount `/target/boot/efi`
95 5. Cd to `/mnt` and run 
96     ```
97     restore /target
98         ```
99     IF you keep backup for several
100     compiters on one disk or want to restore not the latest daily backup,
101     specify backup directory
102     
103         ```
104     restore mynote/beta.1 /target
105         ```
106 6. Reboot and enjoy.
107
108 Other uses
109 ----------
110
111 You can use this restoration procedure when you are upgrading your main
112 SSD - no need to search for USB SATA or USB NVME controller to copy data
113 from old disk. That is why we don't create partitions from script. User
114 may want to rearrange partition layout or just restore system on bigger
115 drive.