mirror cantonese + two more articles
[robinkrens.nl] / docs / backups.txt
1 Simple Backups
2 ********
3
4 Don't forget to make backups folks! I strongly argue against cloud backup services, because most of the time you have no clue _how_ and _where_ data is being backed up. Besides that, it's really not that hard to do it yourself. If you are not running a server with >1000 people, you would probably just do fine backing up your home directory. 
5
6 How to backup?
7 ============
8
9 A simple backup archive of your home directory: 
10
11         $
12         $ tar --create  --file BACKUP.tar /home/rob
13
14 This creates a so-called *tarball* of your folder. Data from your home directory is written to BACKUP.tar. If you are not that familiar with linux, this is similar to the famous Windows zip file, but without compression. You might have encountered the _tar.gz_ a few times. This is just like a tarball but compressed. We can add the option --auto-compress to compress. Tar automatically recognizes the extension of the file your are writing the backup to and compresses it accordingly. The first line creates a tar.gz file, the second one writes to a zip file.
15
16         $ tar --create --auto-compress --file BACKUP.tar.gz /home/rob
17         $ tar --create --auto-compress --file BACKUP.zip /home/rob
18
19 Where to backup?
20 ===========
21 Good question. Some options:
22
23         * to another folder: if you screw up editing some files in your current working directory
24         * to another partition: if you screw up your filesystem on your current partition 
25         * to another drive: if your current drives gets toasted, i.e. mechanical failure. 
26         * to another computer: if you accidentily burn your house down
27         * to many other computers, aka the cloud: if you want to make sure your data is backed up, but besides that also saved forever and being spread amongst many places around the world, vulnerable for whatever law is set by those countries.
28
29 Option a is similar as the command described above. Just make sure your backup is not in the same folder.
30
31 Option b, c are similar to each other. You can also use the option --directory to write the backup file to another partition or (external) hard drive. The following command writes a compressed tarball of my home directory to my external harddrive mounted out /media/externaldrive:
32
33         $ tar --create --auto-compress \
34         --file /media/externalharddrive/BACKUP.tar.gz /home/rob
35
36 Option d. In this case we just simple copy the file (secure ssh copy) to another computer.
37         
38         $ tar --create --auto-compress --file BACKUP.tar.gz /home/rob
39         $ scp BACKUP.tar.gz rob@1.2.3.4:/var/backups/
40         
41
42 When to backup?
43 ============
44 Another good question. 
45
46         * never
47         * rarely (or manually)
48         * scheduled, cronjobs
49         * on change, inotify
50         * always
51
52 Option b is just manually typing in backup commands a few times a week.
53 For option c you can write a simple shell script (i.e. backup.sh) and put it in _/etc/cron.daily_. For example, the following script would write a daily backup (format like: BACKUP-2019-03-04.tar.gz) to a backup directory
54         
55         #!/bin/bash
56         # write full backups to external drive 
57         BACKUP_OF_DIR=/home/rob
58         WRITE_TO_DIR=/media/external
59         DATE=$(date -I)
60
61         # if directory exist, create an archive
62         if [-d $WRITE_TO_DIR ]; then
63                 tar --create --auto-compress --file $WRITE_TO_DIR/BACKUP-$DATE.tar.gz 
64         fi
65
66         # remove made backups older than 90 days
67         # TODO
68
69
70 Option d: TODO
71         
72 So, option e would be some kind of trojan horse on your computer or device, continuously scanning folders, eating resources and uploading to the cloud.
73
74 Final words
75 =============
76 This article can be viewed as the basics of basics. Of course, there are many other ways to do backups. There are also a few security and performance issues involved. Nonetheless, when and where to backup are equal or even more important.