Success-Backup-Check’s documentation!

Warning

Beta software You are using a software that has not reached a stable version yet. Please beware that interfaces might change, APIs might disappear and general breakage can occur before 1.0.

If you plan to use this software for something important, please read the roadmap, and the issue tracker in Github. If you are unsure about the future of this project, please talk to the developers, or (better yet) get involved with the development of success-backup-check!

About

Move user files on a server from a place where the user has write rights & move it to an archive or backup folder, where to user has no read or write access.

A use case example: Daily backup of a point-of-sale database. So that every point-of-sale device has only the current database in the storage. The 2 server check in the operation when was the last backup & send an email if the current database on the server is to old.

function overview
Backup check

Installation instructions

Requirements

Linux

Debian / Ubuntu:

$ sudo apt-get install smartmontools
Mac

Brew:

$ brew install smartmontools

Install

success-backup-check can be installed using pip:

$ sudo python3 -m pip install git+git://github.com/linuxluigi/success-backup-check.git

This command will fetch the archive and its dependencies from the internet and install them.

Or download it from git and execute:

$ git clone git@github.com:linuxluigi/success-backup-check.git
$ cd success-backup-check
$ python setup.py install --user

You might prefer to install it system-wide. In this case, skip the --user option and execute as superuser by prepending the command with sudo.

Troubleshoot

Only tested on linux & mac, I don’t know this will work correctly on windows machines.

Windows users may find that these command will only works if typed from Python’s installation directory.

Some Linux distributions (e.g. Ubuntu) install Python without installing pip. Please install it before. If you don’t have root privileges, download the get-pip.py script at https://bootstrap.pypa.io/get-pip.py and execute it as python get-pip.py --user.

Config

Config file path: `/etc/success_backup_check.conf`

Complete Example:

[Mail]
From = from@example.com
To = to@example.com
ApiKey = YourSendGridApiKey

[Time]
days = 3

[Server]
ArchivDir = /srv/backup/daily_backup/
mode = active
file_typ = MDB

[BackupDirs]
MyDatabaseDir = /home/user/daily-db
UserWork = /home/user/done/work

[Logging]
log_level = WARNING
log_file = /var/log/succes_backup_check.log

Mail

Mails are send via https://sendgrid.com and need a From & To email address and also the sendgrid api key via ApiKey.:

[Mail]
From = from@example.com
To = to@example.com
ApiKey = YourSendGridApiKey

Time

Right now there is the section [Time] just one option. How many days one folder can be outdated.:

[Time]
days = 3

Server

[Server] is for selecting the master backup path on the server & set the server mode.

  • ArchivDir is the master path in witch the backups are will be save to.
  • mode has 2 values active -> move the files from original path to the backup folder & passive -> just check if the active server has done the work right. The default value is passive
  • file_typ set the typ of files witch should be backup. Examples all databases with the ending MDB.
[Server]
ArchivDir = /srv/backup/daily_backup/
mode = active
file_typ = MDB

BackupDirs

The [BackupDirs] Section set witch directory should be backed up. Every entry is a new directory. On the left side is the name of the new directory on the backup server & on the right side ios the full path of the to back up directory:

[BackupDirs]
MyDatabaseDir = /home/user/daily-db
UserWork = /home/user/done/work

Logging

[Logging] is for selecting the log_level (WARNING, INFO, DEBUG) & where to save to the log_file:

[Logging]
log_level = WARNING
log_file = /var/log/succes_backup_check.log

Usage

To run the program run:

$ success-backup-check

Or an example in crontab. (change your Python version):

$ python3 /usr/local/lib/python3.5/dist-packages/success_backup_check/__main__.py

Parameter

Param Default Value Function
  • -c file
  • -config file
/etc/success_backup_check.conf set the config file path
  • -h
  show the help text
  • –version
  show the version

API Reference

API documentation for the success-backup-check module.

success_backup_check.__main__.get_parser()[source]

Creates a new argument parser.

success_backup_check.__main__.main(args=None)[source]

Main entry point

Parameters:args – list A of arguments as if they were input in the command line. Leave it None to use sys.argv.
success_backup_check.archiv_files.archiv_files(directory, archive_dir, extension='MDB')[source]

Move Files with the default ending extension from dir to archive_dir :param directory: original dir, where the database is right now :param archive_dir: archiv dir, werhe the database will move to :param extension: file ending name, default “MDB”

Returns:

success_backup_check.archiv_files.search_dir(path, extension)[source]
extension with leading point, for example: ”.MDB”
Parameters:
  • path
  • extension
success_backup_check.check_backup.check_backup(directory, days)[source]
Check a Directory if the last modify date is older than n days
Args:
directory: Directory witch will be checked days: modify time in days
Returns: False –> the dir is out of date
True –> everything is fine
success_backup_check.read_config.main(config_path)[source]

Read the config from the file at config_path and return it’s content :param config_path: str complete path of the config file :type config_path: object

Returns:config content
success_backup_check.set_logging.get_logging_level(logging_level)[source]

Change string into logging level. Example “DEBUG” -> logging.DEBUG

Returns:
logging level
“DEBUG” -> logging.DEBUG “INFO” -> logging.INFO “WARNING” -> logging.WARNING default -> logging.WARNING
Return type:object
success_backup_check.set_logging.set_logging(logging_level, log_file)[source]

Setup logging config to log into terminal & log file. Just execute set_logging(logging_level, log_file) and start of the script & every time when logging will use this config.

Parameters:
  • logging_level – string “DEBUG”, “INFO” or “WARNING”
  • log_file – full path of the log file example: “/var/log/mylog.log”
success_backup_check.set_logging.set_logging_minimal(logging_level)[source]

Set logging minimal logging, just writing log to console without saving it into a file. :param logging_level: string “DEBUG”, “INFO” or “WARNING”

success_backup_check.hdd_smart_test.main(config)[source]

HDD SMART test

Parameters:config (object) – config object from read_config
success_backup_check.hdd_smart_test.send_alert_sendmail(TEXT, failed_drives, config)[source]

HDD SMART test

Parameters:
  • TEXT (object) – Message witch should be send
  • config (object) – config object from read_config

Help

Need some help? Write me info@linuxluigi.com

Changelog

Version Content
0.2.0
  • Add documentation
  • Refactor Sourcecode
  • add HDD SMART test
  • add logging
  • add more options to config
  • add -c file_path & --config file_path as program parameter
0.1
  • Init project

License

MIT License

Copyright (c) 2017 Steffen Exler

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Indices and tables