Compare commits

..

6 Commits
dev ... master

Author SHA1 Message Date
Bryan 01aaafddda add to README.md 2020-11-08 12:46:13 -06:00
Bryan 18274ea63a more work on logging 2020-11-06 08:43:32 -06:00
Bryan 4a90626b9b update README.md 2020-11-05 23:38:46 -06:00
Bryan 1b5696f5d0 update README.md 2020-11-05 23:02:40 -06:00
Bryan a1e05a6d91 update README.md 2020-11-05 22:59:22 -06:00
Bryan 7ef6745ec5 uptate install script to display progress 2020-11-04 23:40:36 -06:00
3 changed files with 55 additions and 20 deletions

View File

@ -1,17 +1,36 @@
# borgwrapper
Wrapper to simplify backups with borgbackup
# Installation
-----
# Auto Installation
Copy `config.example` to `config`
Edit `config with your settings`
Edit `systemd timer` files if you want to change backup timing
Follow instructions under Manual Installation to set up prerequisits for database dumps.
Run `./install` from borgwrapper directory
This will install borgwrapper and create a basic setup using one config file.
From there you can modify as you want.
* Create additional config files in `/etc/borgwrapper/`
* Change systemd timer file(s)
* Edit the log rotation
* Other
-----
# Manual Installation
Put the [script](src/borgwrapper) somewhere practical
cp borgwrapper /usr/local/bin/borgwrapper
chown root. /usr/local/bin/borgwrapper
chmod 750 /usr/local/bin/borgwrapper
# Configuration
By default borgwrapper expects the configuration to be located at `/etc/borgwrapper/config`.
An example configuration file is included in [config.example](src/config.example).
Ensure restrictive permissions on this file as it exposes the passphrase.
## Configuration
By default borgwrapper expects the configuration to be located at `/etc/borgwrapper/config`.
An example configuration file is included in [config.example](src/config.example).
Ensure restrictive permissions on this file as it exposes the passphrase.
chown root. config
chmod 600 config
@ -20,10 +39,10 @@ To be able to dump special files there are a few things that need to be done.
### Installed package list
Must have the package **apt-mark** installed.
### MySql Dump
Must have the package **mysqldump** installed.
Must have `.my.cnf` configuration file in `/root` directory.
Must have the package **mysqldump** installed.
Must have `.my.cnf` configuration file in `/root` directory.
Create `.my.cnf` in `/root` directory:
Create `.my.cnf` in `/root` directory:
[mysql]
user="root"
@ -37,8 +56,8 @@ Change permissions of `.my.conf`:
chmod 600 /root/.my.conf
# Scheduling
## systemd
## Scheduling
### systemd
Copy the example systemd [unit files](systemd/) to `/etc/systemd/system/`. Then for each
configuration file in `/etc/borgwrapper/<config_name>` do:
@ -70,11 +89,6 @@ The output will land in
You can just drop files in the directory directly too, without editing via
systemctl. This is better suited for configuration management systems.
You can view the backup logs with:
journalctl -xu borgwrapper-backup@<config_name>
journalctl -xu borgwrapper-verify@<config_name>
If you want to run the tasks manually outside the timers you can just start them like usual
services:
@ -132,3 +146,14 @@ Examples:
(. /etc/borgwrapper/config; export BORG_PASSPHRASE; borg mount "$BORG_REPO" /mnt)
(. /etc/borgwrapper/config; export BORG_PASSPHRASE; borg list "$BORG_REPO")
# Miscellaneous
## Multiple config files
You may have multiple config files. Place all config files you want in `/etc/borgwrapper/config`
Run `./install` from borgwrapper directory and it will update systemd to include the new config files
## Logging
The logs in `/var/log/borgwrapper` are by default rotated daily, keeping 5 logs.
If you want to change that edit `/etc/logrotate/logrotate.d/borgwrapper.conf`

14
install
View File

@ -1,11 +1,13 @@
#! /bin/bash
# Copy borgwrapper to bin directory
echo "Installing borgwrapper in: /usr/local/bin/"
cp -i ./src/borgwrapper /usr/local/bin/borgwrapper
chown root. /usr/local/bin/borgwrapper
chmod 750 /usr/local/bin/borgwrapper
# Make borgwrapper config directory and move config file
echo "Making directory: /etc/borgwrapper"
if [ ! -d /etc/borgwrapper/ ]; then
mkdir /etc/borgwrapper
fi
@ -16,13 +18,17 @@ if [ ! -e ./config ]; then
exit 1
fi
echo "Copying config to: /etc/borgwrapper/config"
cp -i ./config /etc/borgwrapper/config
chown root. /etc/borgwrapper/config
chmod 600 /etc/borgwrapper/config
# Setup systemd
echo "Setting up systemd"
echo "Copying systemd timer and service unit files to: /etc/systemd/system/"
cp ./systemd/*.{timer,service} /etc/systemd/system/
echo "Enabling and starting backup and verify systemd timer units"
for config_file in /etc/borgwrapper/*
do
config_file=$(basename ${config_file})
@ -34,10 +40,13 @@ do
done
# Setup logrotate
echo "Setting up logrotate for borgwrapper log files"
echo "Creating directory: /var/log/borgwrapper/"
if [ ! -d /var/log/borgwrapper ]; then
mkdir /var/log/borgwrapper
fi
echo "Creating logrotate file: /etc/logrotate.d/borgwrapper"
(
cat <<EOF
/var/log/borgwrapper/borgwrapper.log {
@ -55,7 +64,8 @@ EOF
# Done. Display some instructions.
echo
echo "Please edit \"/etc/borgwrapper/config\" to make changes to configuration."
echo
echo "You may have multiple configuration files. Please read documentation."
echo
echo "Read \"README.md\" for more information."
echo
echo "Logs will be stored in \"/var/log/borgwrapper/*\""

View File

@ -55,7 +55,7 @@ save_package_list () {
mkdir -p "${PACKAGE_LIST_DIRECTORY}"
fi
apt-mark showmanual > "${PACKAGE_LIST_DIRECTORY}package-list.txt"
apt-mark showmanual > "${PACKAGE_LIST_DIRECTORY}package-list.txt" | log
}
dump_sql () {
@ -69,7 +69,7 @@ dump_sql () {
fi
log "Dumping mysql databases"
for DB in $(mysql -u 'root' -e 'show databases' -s --skip-column-names); do
mysqldump --single-transaction -u 'root' "${DB}" > "${MYSQL_DUMP_DIRECTORY}${DB}.sql.bak" || err "Error dumping mysql"
{ mysqldump --single-transaction -u 'root' "${DB}" > "${MYSQL_DUMP_DIRECTORY}${DB}.sql.bak" | log; } || err "Error dumping mysql"
done
}
@ -83,7 +83,7 @@ dump_mongo () {
then mkdir -p "${MONGODB_DUMP_DIRECTORY}/mongodump"
fi
log "Dumping mongo database"
mongodump --out "${MONGODB_DUMP_DIRECTORY}/mongodump" || err "Error dumping mongo database"
{ mongodump --out "${MONGODB_DUMP_DIRECTORY}/mongodump" | log; } || err "Error dumping mongo database"
}