Skip to main content

Console application for periodically backing up a single file.

Project description

Simple File Backup

Overview

This module lets you back up a single file periodically. It is possible to configure more than one backup period, and limit the maximum number of backup files to keep (per backup period).

Installation

Install this module with:

pip install simple_file_backup

The module exposes the simple-file-backup command-line application.

Command Line Usage

Access the command line help with simple-file-backup -h:

simple-file-backup -h
usage: simple-file-backup FILE_PATH BACKUP_DIR_PATH [-ext EXT] [-conf CONF]

Console application for periodically backing up a single file.

positional arguments:
  file_path        path of file to back up
  backup_dir_path  path of the directory for the backups

optional arguments:
  -h, --help       show this help message and exit
  -ext EXT         file extension of the backups; default is '.bak'
  -prefix PREFIX   backup file name prefix; default is 'backup'
  -conf FILE       path to an optional config file that defines the backup intervals,
                   subdirectories and file limits; by default hourly, daily, weekly and
                   30-day interval backups are created with 48, 14, 12 and unlimited
                   number of files respectively
  -method METHOD   backup method; the default is 'copy' (simple file copy), for sqlite3
                   database files, use 'sqlite3' to avoid corrupting the backups

A separate subdirectory for every backup period will be created within the passed backup directory.

Configuration File

The configuration file is JSON. Backup subdirectory name, backup period (in hours) and file limit per backup period must be configured. For no file limit, pass "inf" as string.

[
    {
        "dirname": "every_minute",
        "period": 0.166667,
        "limit": 10
    },
    {
        "dirname": "every_hour",
        "period": 1,
        "limit": 24
    },
    {
        "dirname": "every_day",
        "period": 24,
        "limit": 30
    },
    {
        "dirname": "every_30days",
        "period": 720,
        "limit": "inf"
    }
]

Python Example

The module can be imported. It exposes the SimpleFileBackup class. In this use case the configuration must be passed as a list of dicts (with the same scheme as the config JSON file).

from simple_file_backup import SimpleFileBackup

backup_inst = SimpleFileBackup(
    file_path="file_to_back_up.txt",
    backup_dir_path="backup_dir",
    prefix="file_backed_up",  # optional, defaults to "backup"
    extension=".txt"  # optional, defaults to ".bak"
    backup_config=[
        {
            "dirname": "hourly",
            "period": 1,
            "limit": 24
        },
        {
            "dirname": "daily",
            "period": 24,
            "limit": "inf"
        }
    ],  # optional, defaults to the same backup periods as the command line version
    backup_method="copy"  # optional, defaults to "copy" (alternative: "sqlite3")
)

# this gets an asyncio loop, creates the backup tasks and runs the loop forever:
backup_inst.run()

Optionally, if integrating into another asyncio application, the tasks can be created on the existing loop without creating and running the loop with the create_tasks(loop) method.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simple_file_backup-1.1.1.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simple_file_backup-1.1.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file simple_file_backup-1.1.1.tar.gz.

File metadata

  • Download URL: simple_file_backup-1.1.1.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

File hashes

Hashes for simple_file_backup-1.1.1.tar.gz
Algorithm Hash digest
SHA256 4f5a3c5a519f7e8c172640ccfaa8bd1d0fd057d282855181f48670b378f430c3
MD5 859d559dcfb46f9b0a476f979e270648
BLAKE2b-256 b47932155af36de98efe3084917e584cd6c7ed7e28826c279f8ed9b11e08d00f

See more details on using hashes here.

File details

Details for the file simple_file_backup-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: simple_file_backup-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

File hashes

Hashes for simple_file_backup-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 030574ad7fc1d175931caa72e7e8238ed50164460ad6a113c05f3286471a5b28
MD5 79f4702de5976dee9ffaf15d638c3a36
BLAKE2b-256 a2d6e9eab55a3f8424fd8bf620c94f2f458fc4eef06a36664e30cc73a9ee136a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page