понедельник, 27 августа 2018 г.

ABS for Auto BackUp System

Intro

  1. Today's software is buggy.
  2. Because of this my daily rule is "backup all twice and regularly".
This two points make me to write my own (because of 1) backup system (because of 2). I called it Auto Backup System (ABS for short).

In this article I am going to show you how to use it.

Installation

ABS is cross-platform. Because of this you need any installer for it.

Just download ABS. Don't forget to make the downloaded file executable using chmod +x.

This is a shell script written in Tenex C Shell. If you don't trust me, you can read all the script. It's less than 130 lines of code. Also it's available at GitLab.


If you are ready to install ABS, download the script and save it somewhere. For example here: /root/abs/abs

Before configuring ABS, please install Zenity and put it into the directory under the PATH.

 

Configuration

ABS doesn't have a config file. Instead of this it obtains all the configuration from the environment variables.

LIST_FILE

This variable must be a path to a file lists files and directories to put into backups. If you didn't set this variable before running ABS, ABS will create a list file in your home directory. Sample of list file is below.

/usr/home/vblinkov/projects/cdialog4php/
/etc/rc.conf
/boot/loader.conf

 

BACKUPS_DIR

This variable contains a path to directory for storing your backups. If you didn't set it before the first running of ABS, ABS will create such directory inside your home directory too.

 

TEXT_EDITOR

This variable must contain the name (from the PATH) or full path to a text editor. By default it set to pluma. But because it's going to dead I would like to recommend you something like Editor from the DeforaOS project. It's tiny but works and does not crash on Ctrl+S.

 

FILE_MANAGER

Use this variable to set the file manager you want to use to view the BACKUPS_DIR. Defaulted to caja.

If some of described variable is unset ABS will inform you with (WW) warnings in stdout.

If you think that you will be happy with defaults, you may jump right to the Scheduling section. But, to customize ABS, read the next section.

 

Wrapper script

If you want to customize the ABS you, of course, may set the described environment variables right in crontab. But as for me, I don't like long lines in the system cron file. Moreover, it's useful to setup logging for ABS (ABS itself doesn't has logging for simplicity).

I suggest the next wrapper script.



Download and save it, for example to /root/abs/abs.run.sh. It's super easy. It sets the file with a list of files and directories for backing up on a regular manner, a directory to storing backup archives and a more stable text editor. Also, abs.run.sh introduces a lightweight logging.

Scheduling

There is nothing easier for you that configuring of running the abs.run.sh on a periodic basis using cron. For example.

2       */2  *    *     *    root /root/abs/abs.run.sh

I think this is super easy. ABS will run every even hour at the 2nd minute.

Using 

If you configured ABS properly, you will see the next dialog periodically for 22 seconds.

  

In the previous picture you may see the list of directories added to created backup. The Backed up section shows files and directories successfully added to the last backup. The Missing section lists the directories and files listed in LIST_FILE, but missing in your file system.

In case of error or missing some critical environment variables you will see red text. Warnings are blue. Note, that ABS know how to created files and directories. So, some errors, once appeared, may not visit you the second time. Such a auto-repair system. (So, who say that TCSH is too dump for doing complicated work? :-) )

Press OK to dismiss the dialog.

Press View to open the directory with all created backup archives (using FILE_MANAGER).

Press Configure to open the file with the list of directories and files you want to backup using ABS (in TEXT_EDITOR).

That's all

Please, do not hesitate to contact me in case of questions and suggestions concerning the script.