up to 0.2.0
This commit is contained in:
parent
8ebdb4a59b
commit
91d4125f99
63
CHANGELOG.md
Normal file
63
CHANGELOG.md
Normal file
@ -0,0 +1,63 @@
|
||||
# baka 0.2.0
|
||||
|
||||
WARNING! All changes in this version breaks backward capatibility!
|
||||
|
||||
# CLI
|
||||
|
||||
New options:
|
||||
|
||||
- `--config`. Specify your baka.conf file.
|
||||
- `backup --dry-run`. Test configuration without backup.
|
||||
- `remove --list`. Print files to delete.
|
||||
|
||||
Changed:
|
||||
|
||||
- `list` command now has two options `--verbose` and `--help`. Verbose output show Entry name, path and local and remote storages in table view.
|
||||
|
||||
Removed:
|
||||
|
||||
- `show` command. View configuration file directly instead.
|
||||
- `edit` command. Edit configuration file directly instead.
|
||||
- `test` command. Use `backup --dry-run` instead.
|
||||
|
||||
# baka.conf (former name: main.conf)
|
||||
|
||||
Added:
|
||||
|
||||
- Default parameter values now is built in baka. Override it in baka.conf
|
||||
- `entries` variable. You can set entries directory in baka.conf
|
||||
- `filename_format`. Special formatting for filenames.
|
||||
- `autoprefix`. Add automatic prefix to filenames (based on entry file name).
|
||||
- `dir_per_date`. Backups path format. See baka(1).
|
||||
|
||||
Changed:
|
||||
|
||||
- `dest` now is `local` and can be used in baka.conf and entries.
|
||||
- `remote` now is URI (like `[scheme]://[user[:password]]@[host[:port]][/path]`) and can be used in baka.conf and entries.
|
||||
|
||||
Removed:
|
||||
|
||||
- `nf`, use `filename_format` instead
|
||||
- `df`, use `filename_format`
|
||||
- `log_df`, use `log_format` istead
|
||||
|
||||
# Entries
|
||||
|
||||
Added:
|
||||
|
||||
- `local`. This is renamed `dest`.
|
||||
- `remote`. Now you can specify remote storage per entry.
|
||||
- `prefix`. Override filename prefix.
|
||||
- `archive`. Renamed `files`. Archive files into **.tar.gz**.
|
||||
- `copy`. Simple file copy without compression.
|
||||
- `database`. Replacement for `mysql` and `postrges` variables. Provide DB URI.
|
||||
|
||||
Removed:
|
||||
|
||||
- `dest`. Use `local` instead.
|
||||
- `mysql` and `postgres` variables. Use `database` instead.
|
||||
- `files` variable. Use `archve` instead.
|
||||
|
||||
# baka 0.1.2
|
||||
|
||||
Initial release.
|
@ -1,6 +1,6 @@
|
||||
# baka
|
||||
|
||||
Simple and flexible file and database backup software written in Bash.
|
||||
Simple and flexible full backup software written in Bash.
|
||||
|
||||
More info in manuals:
|
||||
|
||||
@ -13,13 +13,13 @@ More info in manuals:
|
||||
Add repository to /etc/apt/sources.list.d/:
|
||||
|
||||
```
|
||||
sudo echo 'deb [arch = all] http://repos.gch.icu/debian testing main' > /etc/apt/sources.list.d/gd-debian.list
|
||||
sudo echo 'deb [arch=all] http://repos.gch.icu/debian testing main' > /etc/apt/sources.list.d/ge.list
|
||||
```
|
||||
|
||||
Add key:
|
||||
|
||||
```
|
||||
curl -s http://repos.gch.icu/DEB-GPG-KEY | sudo gpg --no-default-keyring --keyring gnupg-ring:/etc/apt/trusted.gpg.d/gd-debian.gpg --import
|
||||
curl -s http://repos.gch.icu/DEB-GPG-KEY | sudo gpg --no-default-keyring --keyring gnupg-ring:/etc/apt/trusted.gpg.d/ge.gpg --import
|
||||
```
|
||||
|
||||
Update package list and install baka:
|
||||
|
80
etc/baka/baka.conf
Normal file
80
etc/baka/baka.conf
Normal file
@ -0,0 +1,80 @@
|
||||
# * baka 0.2.0
|
||||
# This is baka.conf example. See baka(1) for more info.
|
||||
|
||||
# Path to lookup Entries.
|
||||
entries = /etc/baka/entries
|
||||
|
||||
# Log file. Default: /var/log/baka
|
||||
log = /var/log/baka
|
||||
|
||||
# Log format.
|
||||
#
|
||||
# Log format actually is `date` format string. See date(1) or
|
||||
# 'date --help' for info.
|
||||
#
|
||||
# Special syntax (palceholdes):
|
||||
# {log} will be replaced with actual log string.
|
||||
#
|
||||
# Result for this example:
|
||||
# [21 Jul 2021 22:53:56 +0300] Backup [Started]
|
||||
log_format = [%d %b %Y %T %z] {log}
|
||||
|
||||
# Filename format.
|
||||
#
|
||||
# Special syntax (placeholders):
|
||||
# {name} replaces with file, directory or database name.
|
||||
# {prefix} replaces with prefix specified in Entry file
|
||||
# or by autoprefix (based on Entry file name).
|
||||
#
|
||||
# Examples:
|
||||
# myprefix_myfiles_20210722-2110.tar.gz
|
||||
# myprefix_mydb_20210722-2110.sql.gz
|
||||
filename_format = {prefix}{name}_%Y%m%d-%H%M
|
||||
|
||||
# Automatic prefix for backups.
|
||||
#
|
||||
# Prefix is based on Entry file name.
|
||||
# You can override autoprefix into Entry variable 'prefix'.
|
||||
autoprefix = true
|
||||
|
||||
# Allow Bash command executing.
|
||||
#
|
||||
# Default: false
|
||||
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
# @@ IT IS POTTENTIALLY DANGEROUS! @@
|
||||
# @@ DO NOT USE UNTRUSTED COMMANDS IN ENTRY! @@
|
||||
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
allow_commands = false
|
||||
|
||||
# Local storage.
|
||||
#
|
||||
# This global 'local' value can be overrided in Entry file.
|
||||
# Backups will be saved into 'local' directory.
|
||||
#local = /backups
|
||||
|
||||
# Create directory per date.
|
||||
#
|
||||
# For example: backup 2022-01-01 will be saved in path
|
||||
# /backups/example.com/2022-01-01/example.com_mybackup_20220101-0000.sql.gz
|
||||
# instead of /backups/example.com/example.com_mybackup_20220101-0000.sql.gz
|
||||
#
|
||||
# `dir_per_date` value is interpretated as path. Use '/' to create nested
|
||||
# hierarсрy. '%Y/%m/%d' will expand to:
|
||||
# /backups/example.com/2022/01/01/example.com_mybackup_20220101-0000.sql.gz
|
||||
dir_per_date = %Y-%m-%d
|
||||
|
||||
# Remote storage.
|
||||
#
|
||||
# Uses URI format: [scheme]://[user[:password]]@[host[:port]][/path]
|
||||
#
|
||||
# Schemas can be:
|
||||
# none no remote storage.
|
||||
# rsync copy files to remote storage via rsync over SSH.
|
||||
# s3 copy files to Amazon S3 or S3 compatible storage via s3cmd.
|
||||
remote = none
|
||||
|
||||
# Local backups live time (in days).
|
||||
#
|
||||
# Used by 'baka remove' command. Files older than 'livetime' days will be
|
||||
# removed.
|
||||
livetime = 30
|
@ -1,79 +1,51 @@
|
||||
# This is an entry. This is part of the configuration of the "baka"
|
||||
# backup software. Here you can set the parameters for backuping the
|
||||
# requred data set. See examples below.
|
||||
#
|
||||
# See `man baka` for more info or visit http://nixhacks.net/baka
|
||||
# * baka 0.2.0
|
||||
# This is Entry file example. See baka(1) for more info.
|
||||
|
||||
# Destination dir.
|
||||
# Local storage.
|
||||
#
|
||||
# This is this required parameter. It will be used if the `local`
|
||||
# parameter is not specified in main.conf. You can specify it only
|
||||
# once in an entry.
|
||||
#
|
||||
# This is the only required parameter. And the only one that can be
|
||||
# specified only once. In addition to the destination folder, at
|
||||
# least one variable with data must be specified. See below.
|
||||
dest = /home/user/backups
|
||||
# Specify path to store local backups.
|
||||
local = /srv/example.org/backups
|
||||
|
||||
# Files or directories to backup.
|
||||
# Remote storage.
|
||||
#
|
||||
# Syntax:
|
||||
# files = /path
|
||||
#
|
||||
# Also you can do this:
|
||||
# files = /path/1 path/2
|
||||
#
|
||||
# You can add the `files` variable as many times as you like.
|
||||
files = /var/www/html
|
||||
# You can override global remote storage configuration there.
|
||||
# See baka(1) or baka.conf example /etc/baka/baka.conf
|
||||
#remote = rsync://backups@123.45.67.89:2022/home/backups
|
||||
|
||||
# Exclusions.
|
||||
# Filename prefix.
|
||||
#
|
||||
# This parameter is in addition to the `files` parameter. With its
|
||||
# help you can specify which files or folders should be excluded
|
||||
# from the backup.
|
||||
#
|
||||
# Syntax:
|
||||
# List files and folders separated by commas without spaces on
|
||||
# one line:
|
||||
# exclude = env,logs,__pycache__
|
||||
#
|
||||
# Or split them into multiple lines:
|
||||
# exclude = env
|
||||
# exclude = logs
|
||||
# exclude = __pycache__
|
||||
exclude = env,logs,__pycache__
|
||||
# If you want override autoprefix set prefix there.
|
||||
prefix = example.org_
|
||||
|
||||
# Databases.
|
||||
# Archive files adn directories.
|
||||
#
|
||||
# baka can dump MariaDB/MySQL (shortcut 'mysql') and PostgreSQL
|
||||
# (shortcut 'postgres') databases.
|
||||
# Files be archived with tar into .tar.gz format.
|
||||
#archive = /srv/http/example.org/public
|
||||
|
||||
# Exclude.
|
||||
#
|
||||
# Syntax:
|
||||
# [dmbs] = host:port:database:user:password
|
||||
# You can exclude some files and directories from archive.
|
||||
# Items can be set in one line comma separated.
|
||||
exclude = backups,logs,env,__pycache__,node_modules
|
||||
|
||||
# Copy file or directory.
|
||||
#
|
||||
# For example:
|
||||
# postgres = localhost:5432:mydb:user:password
|
||||
# Simple copy file of directory via 'cp' without compression.
|
||||
# NOTE: 'exclude' varioable not affects on 'copy'.
|
||||
#copy = /srv/http/example.org/data.zip
|
||||
|
||||
# Database.
|
||||
#
|
||||
# You can use shortened syntax too (use standart host and port):
|
||||
# [dmbs] = host:database:user:password
|
||||
# [dmbs] = database:user:password
|
||||
#
|
||||
# NOTE: that due to the nature of the parser, colons and hash
|
||||
# characters cannot be used in the database password.
|
||||
#mysql = localhost:port:database:user:password
|
||||
#postgres = localhost:port:database:user:password
|
||||
# Dump MySQL/MariaDB or PostgreSQL database. Requisites must be passed as
|
||||
# DB URI. For example:
|
||||
# [schema]://[user[:password]]@[host[:port]]/[database]
|
||||
# Available schemas:
|
||||
# For MySQL/MariaDB: mysql, mariadb
|
||||
# For PostgreSQL: postgresql, postgres, psql
|
||||
database = postgres://user:password@localhost:5432/database
|
||||
|
||||
# Commands.
|
||||
#
|
||||
# In addition to files and databases, baka can execute an
|
||||
# arbitrary Bash command for you.
|
||||
#
|
||||
# For example:
|
||||
# command = echo "Hello, World!"
|
||||
#
|
||||
# This feature is disabled by default and must be added in
|
||||
# the main config.
|
||||
# DON'T USE UNTRUSTED COMMANDS IN ENTRY!
|
||||
# This feature is pottentially dangerous. Make sure that access
|
||||
# to the entries is restricted.
|
||||
#command = echo "Are you sure you want to enable it?"
|
||||
# You can execute any Bash command from Entry. This feature is disabled
|
||||
# by default.
|
||||
#command = /srv/http/example.org/dump.py --save /srv/http/example.org/data.zip
|
||||
|
@ -1,69 +0,0 @@
|
||||
# Log file. Default: /var/log/baka
|
||||
log = /var/log/baka
|
||||
|
||||
# Datetime format in log file. See 'man date'.
|
||||
log_df = %d %b %Y %T %z
|
||||
|
||||
# Log format.
|
||||
#
|
||||
# Syntax:
|
||||
# %time
|
||||
# will be replaced with 'log_df' formatted datetime.
|
||||
# %log
|
||||
# will be replaced with log string.
|
||||
#
|
||||
# Result for this example:
|
||||
# [21 Jul 2021 22:53:56 +0300] Backup [Started]
|
||||
log_format = [%time] %log
|
||||
|
||||
# Datetime format. See 'man date'.
|
||||
# This datetime is used for filenames. Example:
|
||||
# backup_myfiles_20210722-2110.tar.gz
|
||||
df = %Y%m%d-%H%M
|
||||
|
||||
# Archive name format.
|
||||
#
|
||||
# Syntax:
|
||||
# %type
|
||||
# 'backup' for files or 'dump' for databases.
|
||||
# %name
|
||||
# directory or database name.
|
||||
# %time
|
||||
# datetime formatted by 'df' option.
|
||||
#
|
||||
# Examples:
|
||||
# backup_myfiles_20210722-2110.tar.gz
|
||||
# dump_mydb_20210722-2110.sql.gz
|
||||
nf = %type_%name_%time
|
||||
|
||||
# Allow comand executing.
|
||||
#
|
||||
# Default: false
|
||||
#
|
||||
# IT IS POTTENTIALLY DANGEROUS!
|
||||
allow_commands = false
|
||||
|
||||
# Remote storage configuration.
|
||||
#
|
||||
# Remote tranport. Can be 'rsync', 's3' or 'none'.
|
||||
remote = none
|
||||
|
||||
# URI for connection via rsync.
|
||||
#ssh_uri = user@server:/path
|
||||
|
||||
# SSH port on remote server. Default: 22
|
||||
#ssh_port = 22
|
||||
|
||||
# URI for S3 bucket. See 'man s3cmd' for more info.
|
||||
#s3_uri = s3://mybucket/backups
|
||||
|
||||
# Local storage configuration.
|
||||
#
|
||||
# If 'local' is set, the 'dest' options in entries will
|
||||
# be ignored. All backups will be saved into 'local' folder.
|
||||
#local = /path/to/backups_dir
|
||||
|
||||
# Backup live time.
|
||||
#
|
||||
# Used by 'baka remove' command.
|
||||
livetime = 30
|
93
make_dist
93
make_dist
@ -1,93 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Make DEB package!
|
||||
|
||||
[ -d $PWD/dist/ ] && rm -rf dist/
|
||||
[ -f baka_*.deb ] && rm baka_*.deb
|
||||
|
||||
# DIRS
|
||||
|
||||
prefix=dist
|
||||
mkdir -p $prefix/DEBIAN
|
||||
mkdir -p $prefix/usr/bin
|
||||
mkdir -p $prefix/usr/share/bash-completion/completions
|
||||
mkdir -p $prefix/usr/share/man/man1
|
||||
cp -r etc/ dist/
|
||||
|
||||
# BINARIES
|
||||
|
||||
cp baka dist/usr/bin/baka && chmod +x dist/usr/bin/baka
|
||||
cp completion dist/usr/share/bash-completion/completions/baka
|
||||
|
||||
# MANPAGES
|
||||
|
||||
md2man ./manpage.md dist/usr/share/man/man1/baka.1
|
||||
sed -i 's%\.TH "" "" "" "" ""%\.TH BAKA 1 "31 July 2021" "baka 0.1.2"%' dist/usr/share/man/man1/baka.1
|
||||
gzip -9 dist/usr/share/man/man1/baka.1
|
||||
|
||||
# DEBIAN/*
|
||||
|
||||
ver=0.1.2
|
||||
|
||||
cat > dist/DEBIAN/control << EOF
|
||||
Package: baka
|
||||
Version: $ver
|
||||
Section: admin
|
||||
Priority: optional
|
||||
Maintainer: gd <gechandev@gmail.com>
|
||||
Homepage: http://nixhacks.net/baka
|
||||
Architecture: all
|
||||
Depends: rsync, s3cmd
|
||||
Description: Simple backuping tool.
|
||||
Backup files and MySQL/MariaDB and PostgreSQL databases.
|
||||
EOF
|
||||
|
||||
cat > dist/DEBIAN/changelog << EOF
|
||||
baka (0.1.2) testing; urgency=medium
|
||||
|
||||
* Initial release.
|
||||
|
||||
-- gd <gechandesu@gmail.com> Sat, 31 Jul 2021 15:22:17 +0300
|
||||
EOF
|
||||
|
||||
cat > dist/DEBIAN/copyright << EOF
|
||||
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
||||
Upstream-Name: baka
|
||||
Upstream-Contact: http://nixhacks.net/baka
|
||||
Source: http://nixhacks.net/baka
|
||||
|
||||
Files: *
|
||||
Copyright: 2021 gd <gechandev@gmail.com>
|
||||
License: GPL-3.0+
|
||||
|
||||
Files: debian/*
|
||||
Copyright: 2021 gd <gechandev@gmail.com>
|
||||
License: GPL-3.0+
|
||||
|
||||
License: GPL-3.0+
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
.
|
||||
This package is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
.
|
||||
On Debian systems, the complete text of the GNU General
|
||||
Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
|
||||
|
||||
# Please also look if there are files or directories which have a
|
||||
# different copyright/license attached and list them here.
|
||||
# Please avoid picking licenses with terms that are more restrictive than the
|
||||
# packaged work, as it may make Debian's contributions unacceptable upstream.
|
||||
#
|
||||
# If you need, there are some extra license texts available in two places:
|
||||
# /usr/share/debhelper/dh_make/licenses/
|
||||
# /usr/share/common-licenses/
|
||||
EOF
|
||||
|
||||
dpkg-deb --build ./dist baka_$ver.deb
|
210
manpage.md
210
manpage.md
@ -1,210 +0,0 @@
|
||||
## NAME
|
||||
baka \- do files and databases backup.
|
||||
|
||||
## SYNOPSIS
|
||||
baka \[\-\-version | -V\] \[\-\-help | help\] \<command\> \[\<options\>...\]
|
||||
|
||||
## DESCRIPTION
|
||||
baka allows you to backup MariaDB/MySQL and PostgreSQL directories and databases.
|
||||
|
||||
baka is based on handling entries. Processing can be started at once for everyone entries, either only for the selected ones, or for all but the excluded ones.
|
||||
|
||||
baka implements only the mechanism for creating archives with files and database dumps and transferring these files to remote storage using third-party tools (such as rsync, s3cmd). To perform scheduled backups, the command baka it is recommended to install it in the operating system task scheduler. For example cron. Examples of usage are in the section EXAMPLES.
|
||||
|
||||
From the above points and the possibility of customizing a separate entry, it follows that with using baka, you can configure the backup system quite flexibly.
|
||||
|
||||
**ATTENTION**: Despite the laudatory description above, baka should not be regarded as professional backup solutions. Please don't use baka in production-like environments.
|
||||
|
||||
### Basic concepts:
|
||||
|
||||
**Entry**
|
||||
|
||||
Entity describing the elements to be acted upon. There can be any number of these entities. For a more detailed description, see section CONFIGURATION FILES.
|
||||
|
||||
**Remote transport**
|
||||
|
||||
A method for delivering files to a remote storage. In version 0.1.0 it could be sync using rsync, upload files to S3 compatible storage with using the s3cmd utility or 'none', which means refusing to upload files to remote storage.
|
||||
|
||||
## COMMANDS
|
||||
|
||||
**backup**
|
||||
|
||||
Do backup right now. Available options:
|
||||
|
||||
-i, --ignore=<entry> run backup for all entries, except ignored.
|
||||
-e, --entry=<entry> run backup for selected entry.
|
||||
--local force local backup.
|
||||
--no-verify don't check archives integrity.
|
||||
--remove remove old backups (forced).
|
||||
--help, help print help message and exit.
|
||||
|
||||
**list**
|
||||
|
||||
List backup entries. Available options:
|
||||
|
||||
-v, --verbose print entries list verbosely (default).
|
||||
-s, --short short format (names).
|
||||
-S short format (pathes).
|
||||
--help, help print help message and exit.
|
||||
|
||||
**test**
|
||||
|
||||
Test configuration incude all entries. Available options:
|
||||
|
||||
-v, --verbose print output verbosely.
|
||||
--help, help print help message and exit.
|
||||
|
||||
**show**
|
||||
|
||||
Print main configuration.
|
||||
|
||||
**edit**
|
||||
|
||||
Edit main configuration in default text editor.
|
||||
|
||||
**remove**
|
||||
|
||||
Remove old local backups (older than $livetime days). Backup livetime is set in main.conf.
|
||||
|
||||
-f, --force force remove.
|
||||
--help, help show this message and exit.
|
||||
|
||||
## CONFIGURATION FILES
|
||||
### MAIN.CONF
|
||||
|
||||
Default path: /etc/baka/main.conf. This contains the values for the global baka settings.
|
||||
|
||||
Required parameters:
|
||||
|
||||
log log file (/var/log/baka).
|
||||
log_df time format in the log. Example: %d %b %Y %T %z
|
||||
More details in 'man date'.
|
||||
log_format format of the log line. Has special syntax.
|
||||
Example:
|
||||
[%time] %log
|
||||
Here:
|
||||
%time time formatted by 'log_df'.
|
||||
%log data string
|
||||
df time format in file names. See 'man date'
|
||||
nf file name format. Has special syntax.
|
||||
Example:
|
||||
%type_%name_%time
|
||||
Here:
|
||||
%type content type. The archive name will be
|
||||
added word 'dump' for database
|
||||
or 'backup' for files.
|
||||
%name is the name of a directory or database.
|
||||
%time time formatted with 'df'.
|
||||
remote remote transport.
|
||||
livetime the lifetime of old backups (number of days).
|
||||
|
||||
Optional parameters:
|
||||
|
||||
allow_commands flag for executing commands from entries.
|
||||
Default: Disabled
|
||||
ssh_uri URI for SSH connection for rsync.
|
||||
ssh_port specify port if different from standard 22.
|
||||
s3_uri URI to connect to the S3 repository.
|
||||
local local folder to save all backups. Everything
|
||||
'dest' in entries will be ignored.
|
||||
|
||||
### ENTRIES
|
||||
|
||||
By default entries is stored into /etc/baka/entries/ directory in separated files. File name does not matter.
|
||||
|
||||
Here you can set the parameters for backuping the requred data set. See examples below.
|
||||
|
||||
**DESTINATION DIR**
|
||||
|
||||
This is this required parameter. It will be used if the `local` parameter is not specified in main.conf. You can specify it only once in an entry.
|
||||
|
||||
This is the only required parameter. And the only one that can be specified only once. In addition to the destination folder, at least one variable with data must be specified.
|
||||
|
||||
Example:
|
||||
|
||||
dest = /home/user/backups
|
||||
|
||||
**FILES**
|
||||
|
||||
Files or directories to backup. Syntax:
|
||||
|
||||
files = /path
|
||||
|
||||
Also you can do this:
|
||||
|
||||
files = /path/1 path/2
|
||||
|
||||
You can add the `files` variable as many times as you like.
|
||||
|
||||
**EXCLUSIONS**
|
||||
|
||||
This parameter is in addition to the `files` parameter. With its help you can specify which files or folders should be excluded from the backup.
|
||||
|
||||
List files and folders separated by commas without spaces on one line:
|
||||
|
||||
exclude = env,logs,__pycache__
|
||||
|
||||
Or split them into multiple lines:
|
||||
|
||||
exclude = env
|
||||
exclude = logs
|
||||
exclude = __pycache__
|
||||
|
||||
**DATABASES**
|
||||
|
||||
baka can dump MariaDB/MySQL (shortcut 'mysql') and PostgreSQL (shortcut 'postgres') databases.
|
||||
|
||||
Syntax:
|
||||
|
||||
[dmbs] = host:port:database:user:password
|
||||
|
||||
For example:
|
||||
|
||||
postgres = localhost:5432:mydb:user:password
|
||||
|
||||
You can use shortened syntax too (use standart host and port):
|
||||
|
||||
[dmbs] = host:database:user:password
|
||||
[dmbs] = database:user:password
|
||||
|
||||
**NOTE:** That due to the nature of the parser, colons and hash characters cannot be used in the database password.
|
||||
|
||||
**COMMANDS**
|
||||
|
||||
In addition to files and databases, baka can execute an arbitrary Bash command for you. For example:
|
||||
|
||||
command = echo "Hello, World!"
|
||||
|
||||
This feature is disabled by default and must be added in the main config. DON'T USE UNTRUSTED COMMANDS IN ENTRY! This feature is pottentially dangerous. Make sure that access to the entries is restricted.
|
||||
|
||||
## EXAMPLES
|
||||
|
||||
An example of using baka. For example, there are two files in /etc/baka/entries/: example.org and example.com. Files content:
|
||||
|
||||
example.org:
|
||||
|
||||
dest = /home/user/backups/example.org
|
||||
files = /srv/example.org/public
|
||||
exclude = logs, cache
|
||||
|
||||
example.com:
|
||||
|
||||
dest = /home/user/backups/example.com
|
||||
files = /srv/example.org/public
|
||||
files = /srv/example.org/storage
|
||||
mysql = mydb: dbuser: password
|
||||
|
||||
In order to start backing up these sites at different times, let's add two tasks to crontab:
|
||||
|
||||
00 00 * * * /usr/bin/baka backup --entry=example.com
|
||||
00 00 */2 * * /usr/bin/baka backup --entry=example.org
|
||||
|
||||
Likewise, you can start backing up more entries by adding exceptions or specifying specific entries. For example like this:
|
||||
|
||||
baka backup --ignore=example.org --ignore=example.com
|
||||
|
||||
## BUGS
|
||||
Report bugs to <gechandev@gmail.com> or <https://gitea.gch.icu/gd/baka>
|
||||
|
||||
## AUTHOR
|
||||
gd (gechandev@gmail.com)
|
211
manpage.ru.md
211
manpage.ru.md
@ -1,211 +0,0 @@
|
||||
## НАЗВАНИЕ
|
||||
baka \- создание резервных копий файлов и баз данных.
|
||||
|
||||
## ОБЗОР
|
||||
baka \[\-\-version | -V\] \[\-\-help | help\] \<command\> \[\<options\>...\]
|
||||
|
||||
## ОПИСАНИЕ
|
||||
baka позволяет создавать резервные копии каталогов и баз данных MariaDB/MySQL и PostgreSQL.
|
||||
|
||||
Работа baka базируется на обработке записей (entries). Обработка может быть запущена сразу для всех записей, либо только для выбранных, либо для всех, кроме исключенных.
|
||||
|
||||
baka реализует только механизм создания архивов с файлами и дампами баз данных и передачи этих файлов в удаленное хранилище с помощью сторонних инструментов (таких как rsync, s3cmd). Для выполнения резервного копирования по расписанию, команду baka рекомендуется установить в планировщике задач операционной системы. Например cron. Примеры использования находятся в разделе ПРИМЕРЫ.
|
||||
|
||||
Из вышеперечисленных пунктов и возможности настройки отдельной записи следует, что с помощью baka можно довольно гибко настроить систему резервного копирования.
|
||||
|
||||
**ВНИМАНИЕ**: Несмотря на красивое описание выше, baka не следует рассматривать как профессиональные решения для резервного копирования. Пожалуйста, не используйте baka в продакшн среде.
|
||||
|
||||
### Основные понятия:
|
||||
|
||||
**Entry**
|
||||
|
||||
Сущность, описывающая элементы, с которыми нужно выполнять действия. Таких сущностей может быть любое количество. Более подробное описание см. В разделе КОНФИГУРАЦИОННЫЕ ФАЙЛЫ.
|
||||
|
||||
**Remote transport**
|
||||
|
||||
Способ доставки файлов в удаленное хранилище. В версии 0.1 это может быть синхронизация с помощью rsync, загрузка файлов в S3-совместимое хранилище с помощью утилиты s3cmd или «none», что означает отказ от загрузки файлов в удаленное хранилище.
|
||||
|
||||
## КОМАНДЫ
|
||||
|
||||
**backup**
|
||||
|
||||
Сделать резервную копию прямо сейчас. Доступные опции:
|
||||
|
||||
-i, --ignore=<entry> запустить резервное копирование для всех записей,
|
||||
кроме игнорируемых.
|
||||
-e, --entry=<entry> запустить резервное копирование выбранной записи.
|
||||
--local принудительное локальное резервное копирование.
|
||||
--no-verify не проверять целостность архивов.
|
||||
--remove удалить старые резервные копии (принудительно).
|
||||
--help, help напечатать справочное сообщение и выйти.
|
||||
|
||||
**list**
|
||||
|
||||
Список доступных entries. Доступные опции:
|
||||
|
||||
-v, --verbose выводить список записей подробно (по умолчанию).
|
||||
-s, --short короткий формат (имена).
|
||||
-S короткий формат (пути).
|
||||
--help, help напечатать справочное сообщение и выйти.
|
||||
|
||||
**test**
|
||||
|
||||
Проверка конфигурации main.conf и всех entries. Доступные опции:
|
||||
|
||||
-v, --verbose выводить на печать подробный вывод.
|
||||
--help, help напечатать справочное сообщение и выйти.
|
||||
|
||||
**show**
|
||||
|
||||
Распечатать основную конфигурацию (main.conf).
|
||||
|
||||
**edit**
|
||||
|
||||
Открыть main.conf в текстовом редакторе по умолчанию.
|
||||
|
||||
**remove**
|
||||
|
||||
Удалить старые локальные резервные копии (старше чем $livetime дней). Время жизни резервной копии устанавливается в main.conf.
|
||||
|
||||
-f, --force удалить без подтверждения.
|
||||
--help, help напечатать справочное сообщение и выйти.
|
||||
|
||||
## КОНФИГУРАЦИОННЫЕ ФАЙЛЫ
|
||||
### MAIN.CONF
|
||||
|
||||
Путь к файлу: /etc/baka/main.conf. Он содержит значения для глобальных настроек baka.
|
||||
|
||||
Обязательные параметры:
|
||||
|
||||
log файл лога (/var/log/baka).
|
||||
log_df формат времени в логе. Пример: %d %b %Y %T %z
|
||||
Подробнее в 'man date'.
|
||||
log_format формат строки лога. Имеет специальный синтаксис.
|
||||
Пример:
|
||||
[%time] %log
|
||||
Здесь:
|
||||
%time время, отформатирвованное по 'log_df'.
|
||||
%log строка с данными
|
||||
df формат времени в именах файлов. См. 'man date'
|
||||
nf формат имён файлов. Имеет специальный синтаксис.
|
||||
Пример:
|
||||
%type_%name_%time
|
||||
Здесь:
|
||||
%type тип содержимого. К имени архива будет
|
||||
добавлено слово 'dump' для базы данных
|
||||
или 'backup' для файлов.
|
||||
%name имя директории или базы данных.
|
||||
%time время, отформатированное по 'df'.
|
||||
remote remote transport.
|
||||
livetime время жизни старых бэкапов (количество дней).
|
||||
|
||||
Опциональные параметры:
|
||||
|
||||
allow_commands флаг для выполнения команд из entries.
|
||||
По-умолчанию: отключено
|
||||
ssh_uri URI для подключения по SSH для rsync.
|
||||
ssh_port указать порт, если отличается от стандартного 22.
|
||||
s3_uri URI для подключения к хранилищу S3.
|
||||
local локальная папка для сохранения всех бэкапов. Все
|
||||
'dest' в entries будут проигнорированы.
|
||||
|
||||
### ЗАПИСИ (ENTRIES)
|
||||
|
||||
Записи хранятся в каталоге /etc/baka/entries/ в отдельных файлах. Имя файла значения не имеет.
|
||||
|
||||
В них вы можете установить параметры резервного копирования нужного набора данных. См. примеры ниже.
|
||||
|
||||
**DESTINATION DIR**
|
||||
|
||||
Локальная целевая папка. В неё будут сохранены данные, которые описаны в записи. Это обязательный параметр. Он будет использоваться, если параметр `local` не указан в main.conf. Вы можете указать его только один раз в записи.
|
||||
|
||||
Это единственный обязательный параметр. И единственный, который можно указать только один раз. В дополнение к целевой папке должна быть указана хотя бы одна переменная с данными.
|
||||
|
||||
Пример:
|
||||
|
||||
dest = /home/user/backups
|
||||
|
||||
**FILES**
|
||||
|
||||
Файлы или каталоги для резервного копирования. Синтаксис:
|
||||
|
||||
files = /path
|
||||
|
||||
Также вы можете сделать так:
|
||||
|
||||
files = /path/1 /path/2
|
||||
|
||||
Вы можете добавлять переменную `files` сколько угодно раз.
|
||||
|
||||
**EXCLUSIONS**
|
||||
|
||||
Этот параметр является дополнением к параметру files. С его помощью вы можете указать, какие файлы или папки следует исключить из резервной копии.
|
||||
|
||||
Перечислить файлы и папки через запятую без пробелов в одной строке:
|
||||
|
||||
exclude = env,logs,__ pycache__
|
||||
|
||||
Или разделите их на несколько строк:
|
||||
|
||||
exclude = env
|
||||
exclude = logs
|
||||
exclude = __pycache__
|
||||
|
||||
**DATABASES**
|
||||
|
||||
baka может сделать базы данных MariaDB/MySQL (ярлык mysql) и PostgreSQL (ярлык postgres).
|
||||
|
||||
Синтаксис:
|
||||
|
||||
[dmbs] = host:port:database:user:password
|
||||
|
||||
Например:
|
||||
|
||||
postgres = localhost:5432:mydb:user:password
|
||||
|
||||
Вы также можете использовать сокращенный синтаксис (используйте стандартный хост и порт):
|
||||
|
||||
[dmbs] = host:database:user:password
|
||||
[dmbs] = database:user:password
|
||||
|
||||
**ПРИМЕЧАНИЕ:** Из-за особенностей парсера двоеточия и символы решетки не могут использоваться в пароле базы данных.
|
||||
|
||||
**COMMANDS**
|
||||
|
||||
Помимо файлов и баз данных, baka может выполнять для вас произвольную команду Bash. Например:
|
||||
|
||||
command = echo "Привет, мир!"
|
||||
|
||||
Эта функция отключена по умолчанию и может быть включена в main.conf. НЕ ИСПОЛЬЗУЙТЕ НЕДОВЕРЕННЫЕ КОМАНДЫ В ENTRY! Эта функция потенциально опасна. Убедитесь, что доступ к записям ограничен.
|
||||
|
||||
## ПРИМЕРЫ
|
||||
|
||||
Пример использования baka. Например, есть два файла в /etc/baka/entries: example.org и example.com. Содержимое файлов:
|
||||
|
||||
example.org:
|
||||
|
||||
dest = /home/user/backups/example.org
|
||||
files = /srv/example.org/public
|
||||
exclude = logs,cache
|
||||
|
||||
example.com:
|
||||
|
||||
dest = /home/user/backups/example.com
|
||||
files = /srv/example.org/public
|
||||
files = /srv/example.org/storage
|
||||
mysql = mydb:dbuser:password
|
||||
|
||||
Для того, чтобы заапускать резервное копирование этих сайтов в разное время, добавим в crontab две задачи:
|
||||
|
||||
00 00 * * * /usr/bin/baka backup --entry=example.com
|
||||
00 00 */2 * * /usr/bin/baka backup --entry=example.org
|
||||
|
||||
Точно таким же образом можно запускать резервное копирование большего числа entries, добавляя исключения или указывая конкретные entries. Например так:
|
||||
|
||||
baka backup --ignore=example.org --ignore=example.com
|
||||
|
||||
## ОШИБКИ
|
||||
Сообщайте об ошибках на <gechandev@gmail.com> или <https://gitea.gch.icu/gd/baka>
|
||||
ё
|
||||
## АВТОР
|
||||
gd (gechandev@gmail.com)
|
161
mkdist
Executable file
161
mkdist
Executable file
@ -0,0 +1,161 @@
|
||||
#!/usr/bin/env bash
|
||||
# Make DEB package!
|
||||
|
||||
ver=0.2.0
|
||||
credit='ge <me@nixhacks.net>'
|
||||
|
||||
[ -d $PWD/dist/ ] && rm -rf dist/
|
||||
[ -f baka_*.deb ] && rm baka_*.deb
|
||||
|
||||
# DIRS
|
||||
|
||||
prefix=dist
|
||||
mkdir -p $prefix/DEBIAN
|
||||
mkdir -p $prefix/usr/bin
|
||||
mkdir -p $prefix/usr/share/bash-completion/completions
|
||||
mkdir -p $prefix/usr/share/man/man1
|
||||
cp -r etc/ $prefix
|
||||
|
||||
# BINARIES
|
||||
|
||||
cp src/baka $prefix/usr/bin/baka && chmod +x $prefix/usr/bin/baka
|
||||
cp src/completion $prefix/usr/share/bash-completion/completions/baka
|
||||
|
||||
# MANPAGES
|
||||
|
||||
pandoc --from=markdown --to=man --standalone \
|
||||
docs/baka.1.md --output=$prefix/usr/share/man/man1/baka.1
|
||||
|
||||
c=`date +'%d %b %Y'`
|
||||
sed -i "s%\.TH \"\" \"\" \"\" \"\" \"\"%\.TH BAKA 1 \"$c\" \"baka $ver\"%" $prefix/usr/share/man/man1/baka.1
|
||||
gzip -9 $prefix/usr/share/man/man1/baka.1
|
||||
|
||||
# DEBIAN/*
|
||||
|
||||
cat > $prefix/DEBIAN/control << EOF
|
||||
Package: baka
|
||||
Version: $ver
|
||||
Section: admin
|
||||
Priority: optional
|
||||
Maintainer: $credit
|
||||
Homepage: http://nixhacks.net/baka
|
||||
Architecture: all
|
||||
Depends: rsync, s3cmd
|
||||
Description: Simple backuping tool.
|
||||
Backup files and MySQL/MariaDB and PostgreSQL databases.
|
||||
EOF
|
||||
|
||||
cat > $prefix/DEBIAN/changelog << EOF
|
||||
baka (0.2.0) testing; urgency=medium
|
||||
|
||||
* Code refactoring.
|
||||
|
||||
WARNING! All changes in this version breaks backward capatibility!
|
||||
|
||||
# CLI
|
||||
|
||||
New options:
|
||||
|
||||
- '--config'. Specify your baka.conf file.
|
||||
- 'backup --dry-run'. Test configuration without backup.
|
||||
- 'remove --list'. Print files to delete.
|
||||
|
||||
Changed:
|
||||
|
||||
- 'list' command now has two options '--verbose' and '--help'. Verbose output show Entry name, path and local and remote storages in table view.
|
||||
|
||||
Removed:
|
||||
|
||||
- 'show' command. View configuration file directly instead.
|
||||
- 'edit' command. Edit configuration file directly instead.
|
||||
- 'test' command. Use 'backup --dry-run' instead.
|
||||
|
||||
# baka.conf (former name: main.conf)
|
||||
|
||||
Added:
|
||||
|
||||
- Default parameter values now is built in baka. Override it in baka.conf
|
||||
- 'entries' variable. You can set entries directory in baka.conf
|
||||
- 'filename_format'. Special formatting for filenames.
|
||||
- 'autoprefix'. Add automatic prefix to filenames (based on entry file name).
|
||||
- 'dir_per_date'. Backups path format. See baka(1).
|
||||
|
||||
Changed:
|
||||
|
||||
- 'dest' now is 'local' and can be used in baka.conf and entries.
|
||||
- 'remote' now is URI (like '[scheme]://[user[:password]]@[host[:port]][/path]') and can be used in baka.conf and entries.
|
||||
|
||||
Removed:
|
||||
|
||||
- 'nf', use 'filename_format' instead
|
||||
- 'df', use 'filename_format'
|
||||
- 'log_df', use 'log_format' istead
|
||||
|
||||
# Entries
|
||||
|
||||
Added:
|
||||
|
||||
- 'local'. This is renamed 'dest'.
|
||||
- 'remote'. Now you can specify remote storage per entry.
|
||||
- 'prefix'. Override filename prefix.
|
||||
- 'archive'. Renamed 'files'. Archive files into **.tar.gz**.
|
||||
- 'copy'. Simple file copy without compression.
|
||||
- 'database'. Replacement for 'mysql' and 'postrges' variables. Provide DB URI.
|
||||
|
||||
Removed:
|
||||
|
||||
- 'dest'. Use 'local' instead.
|
||||
- 'mysql' and 'postgres' variables. Use 'database' instead.
|
||||
- 'files' variable. Use 'archve' instead.
|
||||
|
||||
-- $credit `date -R`
|
||||
|
||||
baka (0.1.2) testing; urgency=medium
|
||||
|
||||
* Initial release.
|
||||
|
||||
-- $credit Sat, 31 Jul 2021 15:22:17 +0300
|
||||
EOF
|
||||
|
||||
cat > $prefix/DEBIAN/copyright << EOF
|
||||
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
||||
Upstream-Name: baka
|
||||
Upstream-Contact: http://nixhacks.net/baka
|
||||
Source: http://nixhacks.net/baka
|
||||
|
||||
Files: *
|
||||
Copyright: `date +%Y` $credit
|
||||
License: GPL-3.0+
|
||||
|
||||
Files: debian/*
|
||||
Copyright: `date +%Y` $credit
|
||||
License: GPL-3.0+
|
||||
|
||||
License: GPL-3.0+
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
.
|
||||
This package is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
.
|
||||
On Debian systems, the complete text of the GNU General
|
||||
Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
|
||||
|
||||
# Please also look if there are files or directories which have a
|
||||
# different copyright/license attached and list them here.
|
||||
# Please avoid picking licenses with terms that are more restrictive than the
|
||||
# packaged work, as it may make Debian's contributions unacceptable upstream.
|
||||
#
|
||||
# If you need, there are some extra license texts available in two places:
|
||||
# /usr/share/debhelper/dh_make/licenses/
|
||||
# /usr/share/common-licenses/
|
||||
EOF
|
||||
|
||||
dpkg-deb --build $prefix baka_$ver.deb
|
@ -1,16 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
# baka completion script.
|
||||
# * baka (v 0.2.0) completion script.
|
||||
|
||||
baka_get_entries() {
|
||||
_baka_get_entries() {
|
||||
# Collect entries list from /etc/baka/entries
|
||||
baka_entries=./entries # /etc/baka/entries
|
||||
|
||||
baka_entries=/etc/baka/entries
|
||||
|
||||
# This is just baka bk_find_entries() function copy-paste.
|
||||
|
||||
local all_files="$(find "$baka_entries" -type f)"
|
||||
|
||||
for file in $all_files
|
||||
do
|
||||
for file in $all_files; do
|
||||
# Resolve symlinks.
|
||||
if [ -L "$file" ]; then
|
||||
s="$(readlink "$file")"
|
||||
@ -19,47 +19,44 @@ baka_get_entries() {
|
||||
fi
|
||||
fi
|
||||
# Collect all entries, except ignored if set.
|
||||
if [[ ! "${ignore[@]}" =~ "$(basename $file)" ]]
|
||||
then
|
||||
bk_all_entries+=("${file##*/}")
|
||||
if [[ ! "${ignore[@]}" =~ "$(basename $file)" ]]; then
|
||||
all_entries+=("${file##*/}")
|
||||
fi
|
||||
done
|
||||
|
||||
echo "${bk_all_entries[@]}"
|
||||
echo "${all_entries[@]}"
|
||||
}
|
||||
|
||||
baka_completion() {
|
||||
_baka() {
|
||||
local cur prev
|
||||
cur=${COMP_WORDS[COMP_CWORD]}
|
||||
prev=${COMP_WORDS[COMP_CWORD-1]}
|
||||
|
||||
case ${COMP_CWORD} in
|
||||
1)
|
||||
1|3)
|
||||
# Firs level commands.
|
||||
COMPREPLY=($(compgen -W \
|
||||
"help --help --version
|
||||
backup list test show edit remove" -- ${cur}))
|
||||
"help --help --version -c --config
|
||||
backup list remove" -- ${cur}))
|
||||
;;
|
||||
2)
|
||||
2|4)
|
||||
# Subcommands.
|
||||
case ${prev} in
|
||||
backup)
|
||||
COMPREPLY=($(compgen -W \
|
||||
"help --help -i --ignore -e --entry
|
||||
--local --no-verify --remove" -- ${cur}))
|
||||
--local --no-verify --dry-run --remove" -- ${cur}))
|
||||
;;
|
||||
list)
|
||||
COMPREPLY=($(compgen -W \
|
||||
"help --help
|
||||
--verbose -v --short -s -S" -- ${cur}))
|
||||
;;
|
||||
test)
|
||||
COMPREPLY=($(compgen -W \
|
||||
"help --help --verbose -v" -- ${cur}))
|
||||
"help --help -v --verbose" -- ${cur}))
|
||||
;;
|
||||
remove)
|
||||
COMPREPLY=($(compgen -W \
|
||||
"help --help --force -f" -- ${cur}))
|
||||
"help --help -f --force -l --list" -- ${cur}))
|
||||
;;
|
||||
-c|--config|--config=)
|
||||
compopt -o default; COMPREPLY=()
|
||||
;;
|
||||
*) COMPREPLY=()
|
||||
;;
|
||||
@ -69,7 +66,7 @@ baka_completion() {
|
||||
# Subcommand options completion.
|
||||
case ${COMP_WORDS[2]} in
|
||||
-i|--ignore|--ignore=|-e|--entry|--entry=)
|
||||
entries_list="$(baka_get_entries)"
|
||||
entries_list="$(_baka_get_entries)"
|
||||
COMPREPLY=($(compgen -W \
|
||||
"$entries_list" -- ${cur}))
|
||||
;;
|
||||
@ -84,4 +81,4 @@ baka_completion() {
|
||||
esac
|
||||
}
|
||||
|
||||
complete -F baka_completion baka
|
||||
complete -F _baka baka ./baka
|
Reference in New Issue
Block a user