Simple Backups

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.

How to backup?

A simple backup archive of your home directory:

        $
        $ tar --create  --file BACKUP.tar /home/rob

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.

        $ tar --create --auto-compress --file BACKUP.tar.gz /home/rob
        $ tar --create --auto-compress --file BACKUP.zip /home/rob

Where to backup?

Good question. Some options:

Option a is similar as the command described above. Just make sure your backup is not in the same folder.

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:

        $ tar --create --auto-compress \
        --file /media/externalharddrive/BACKUP.tar.gz /home/rob

Option d. In this case we just simple copy the file (secure ssh copy) to another computer.

        $ tar --create --auto-compress --file BACKUP.tar.gz /home/rob
        $ scp BACKUP.tar.gz rob@1.2.3.4:/var/backups/

When to backup?

Another good question.

Option b is just manually typing in backup commands a few times a week. 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

        #!/bin/bash
        # write full backups to external drive 
        BACKUP_OF_DIR=/home/rob
        WRITE_TO_DIR=/media/external
        DATE=$(date -I)

        # if directory exist, create an archive
        if [-d $WRITE_TO_DIR ]; then
                tar --create --auto-compress --file $WRITE_TO_DIR/BACKUP-$DATE.tar.gz 
        fi

        # remove made backups older than 90 days
        # TODO

Option d: TODO

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.

Final words

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.