Compare commits
No commits in common. "master" and "dev" have entirely different histories.
55
README.md
55
README.md
|
|
@ -1,36 +1,17 @@
|
|||
# borgwrapper
|
||||
Wrapper to simplify backups with borgbackup
|
||||
|
||||
-----
|
||||
# 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
|
||||
|
||||
# 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
|
||||
|
|
@ -39,10 +20,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"
|
||||
|
|
@ -56,8 +37,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:
|
||||
|
||||
|
|
@ -89,6 +70,11 @@ 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:
|
||||
|
||||
|
|
@ -146,14 +132,3 @@ 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
14
install
|
|
@ -1,13 +1,11 @@
|
|||
#! /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
|
||||
|
|
@ -18,17 +16,13 @@ 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})
|
||||
|
|
@ -40,13 +34,10 @@ 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 {
|
||||
|
|
@ -64,8 +55,7 @@ EOF
|
|||
# Done. Display some instructions.
|
||||
echo
|
||||
echo "Please edit \"/etc/borgwrapper/config\" to make changes to configuration."
|
||||
echo "You may have multiple configuration files. Please read documentation."
|
||||
echo
|
||||
echo
|
||||
echo "Read \"README.md\" for more information."
|
||||
echo
|
||||
echo "Logs will be stored in \"/var/log/borgwrapper/*\""
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ save_package_list () {
|
|||
mkdir -p "${PACKAGE_LIST_DIRECTORY}"
|
||||
fi
|
||||
|
||||
apt-mark showmanual > "${PACKAGE_LIST_DIRECTORY}package-list.txt" | log
|
||||
apt-mark showmanual > "${PACKAGE_LIST_DIRECTORY}package-list.txt"
|
||||
}
|
||||
|
||||
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" | log; } || err "Error dumping mysql"
|
||||
mysqldump --single-transaction -u 'root' "${DB}" > "${MYSQL_DUMP_DIRECTORY}${DB}.sql.bak" || 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" | log; } || err "Error dumping mongo database"
|
||||
mongodump --out "${MONGODB_DUMP_DIRECTORY}/mongodump" || err "Error dumping mongo database"
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue