Compare commits
No commits in common. "master" and "dev" have entirely different histories.
55
README.md
55
README.md
|
|
@ -1,36 +1,17 @@
|
||||||
# borgwrapper
|
# borgwrapper
|
||||||
Wrapper to simplify backups with borgbackup
|
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
|
Put the [script](src/borgwrapper) somewhere practical
|
||||||
|
|
||||||
cp borgwrapper /usr/local/bin/borgwrapper
|
cp borgwrapper /usr/local/bin/borgwrapper
|
||||||
chown root. /usr/local/bin/borgwrapper
|
chown root. /usr/local/bin/borgwrapper
|
||||||
chmod 750 /usr/local/bin/borgwrapper
|
chmod 750 /usr/local/bin/borgwrapper
|
||||||
|
|
||||||
## Configuration
|
# Configuration
|
||||||
By default borgwrapper expects the configuration to be located at `/etc/borgwrapper/config`.
|
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).
|
An example configuration file is included in [config.example](src/config.example).
|
||||||
Ensure restrictive permissions on this file as it exposes the passphrase.
|
Ensure restrictive permissions on this file as it exposes the passphrase.
|
||||||
|
|
||||||
chown root. config
|
chown root. config
|
||||||
chmod 600 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
|
### Installed package list
|
||||||
Must have the package **apt-mark** installed.
|
Must have the package **apt-mark** installed.
|
||||||
### MySql Dump
|
### MySql Dump
|
||||||
Must have the package **mysqldump** installed.
|
Must have the package **mysqldump** installed.
|
||||||
Must have `.my.cnf` configuration file in `/root` directory.
|
Must have `.my.cnf` configuration file in `/root` directory.
|
||||||
|
|
||||||
Create `.my.cnf` in `/root` directory:
|
Create `.my.cnf` in `/root` directory:
|
||||||
|
|
||||||
[mysql]
|
[mysql]
|
||||||
user="root"
|
user="root"
|
||||||
|
|
@ -56,8 +37,8 @@ Change permissions of `.my.conf`:
|
||||||
|
|
||||||
chmod 600 /root/.my.conf
|
chmod 600 /root/.my.conf
|
||||||
|
|
||||||
## Scheduling
|
# Scheduling
|
||||||
### systemd
|
## systemd
|
||||||
Copy the example systemd [unit files](systemd/) to `/etc/systemd/system/`. Then for each
|
Copy the example systemd [unit files](systemd/) to `/etc/systemd/system/`. Then for each
|
||||||
configuration file in `/etc/borgwrapper/<config_name>` do:
|
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
|
You can just drop files in the directory directly too, without editing via
|
||||||
systemctl. This is better suited for configuration management systems.
|
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
|
If you want to run the tasks manually outside the timers you can just start them like usual
|
||||||
services:
|
services:
|
||||||
|
|
||||||
|
|
@ -146,14 +132,3 @@ Examples:
|
||||||
|
|
||||||
(. /etc/borgwrapper/config; export BORG_PASSPHRASE; borg mount "$BORG_REPO" /mnt)
|
(. /etc/borgwrapper/config; export BORG_PASSPHRASE; borg mount "$BORG_REPO" /mnt)
|
||||||
(. /etc/borgwrapper/config; export BORG_PASSPHRASE; borg list "$BORG_REPO")
|
(. /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
|
#! /bin/bash
|
||||||
|
|
||||||
# Copy borgwrapper to bin directory
|
# Copy borgwrapper to bin directory
|
||||||
echo "Installing borgwrapper in: /usr/local/bin/"
|
|
||||||
cp -i ./src/borgwrapper /usr/local/bin/borgwrapper
|
cp -i ./src/borgwrapper /usr/local/bin/borgwrapper
|
||||||
chown root. /usr/local/bin/borgwrapper
|
chown root. /usr/local/bin/borgwrapper
|
||||||
chmod 750 /usr/local/bin/borgwrapper
|
chmod 750 /usr/local/bin/borgwrapper
|
||||||
|
|
||||||
# Make borgwrapper config directory and move config file
|
# Make borgwrapper config directory and move config file
|
||||||
echo "Making directory: /etc/borgwrapper"
|
|
||||||
if [ ! -d /etc/borgwrapper/ ]; then
|
if [ ! -d /etc/borgwrapper/ ]; then
|
||||||
mkdir /etc/borgwrapper
|
mkdir /etc/borgwrapper
|
||||||
fi
|
fi
|
||||||
|
|
@ -18,17 +16,13 @@ if [ ! -e ./config ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Copying config to: /etc/borgwrapper/config"
|
|
||||||
cp -i ./config /etc/borgwrapper/config
|
cp -i ./config /etc/borgwrapper/config
|
||||||
chown root. /etc/borgwrapper/config
|
chown root. /etc/borgwrapper/config
|
||||||
chmod 600 /etc/borgwrapper/config
|
chmod 600 /etc/borgwrapper/config
|
||||||
|
|
||||||
# Setup systemd
|
# 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/
|
cp ./systemd/*.{timer,service} /etc/systemd/system/
|
||||||
|
|
||||||
echo "Enabling and starting backup and verify systemd timer units"
|
|
||||||
for config_file in /etc/borgwrapper/*
|
for config_file in /etc/borgwrapper/*
|
||||||
do
|
do
|
||||||
config_file=$(basename ${config_file})
|
config_file=$(basename ${config_file})
|
||||||
|
|
@ -40,13 +34,10 @@ do
|
||||||
done
|
done
|
||||||
|
|
||||||
# Setup logrotate
|
# Setup logrotate
|
||||||
echo "Setting up logrotate for borgwrapper log files"
|
|
||||||
echo "Creating directory: /var/log/borgwrapper/"
|
|
||||||
if [ ! -d /var/log/borgwrapper ]; then
|
if [ ! -d /var/log/borgwrapper ]; then
|
||||||
mkdir /var/log/borgwrapper
|
mkdir /var/log/borgwrapper
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Creating logrotate file: /etc/logrotate.d/borgwrapper"
|
|
||||||
(
|
(
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
/var/log/borgwrapper/borgwrapper.log {
|
/var/log/borgwrapper/borgwrapper.log {
|
||||||
|
|
@ -64,8 +55,7 @@ EOF
|
||||||
# Done. Display some instructions.
|
# Done. Display some instructions.
|
||||||
echo
|
echo
|
||||||
echo "Please edit \"/etc/borgwrapper/config\" to make changes to configuration."
|
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 "Read \"README.md\" for more information."
|
||||||
echo
|
echo
|
||||||
echo "Logs will be stored in \"/var/log/borgwrapper/*\""
|
echo "Logs will be stored in \"/var/log/borgwrapper/*\""
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ save_package_list () {
|
||||||
mkdir -p "${PACKAGE_LIST_DIRECTORY}"
|
mkdir -p "${PACKAGE_LIST_DIRECTORY}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
apt-mark showmanual > "${PACKAGE_LIST_DIRECTORY}package-list.txt" | log
|
apt-mark showmanual > "${PACKAGE_LIST_DIRECTORY}package-list.txt"
|
||||||
}
|
}
|
||||||
|
|
||||||
dump_sql () {
|
dump_sql () {
|
||||||
|
|
@ -69,7 +69,7 @@ dump_sql () {
|
||||||
fi
|
fi
|
||||||
log "Dumping mysql databases"
|
log "Dumping mysql databases"
|
||||||
for DB in $(mysql -u 'root' -e 'show databases' -s --skip-column-names); do
|
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
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -83,7 +83,7 @@ dump_mongo () {
|
||||||
then mkdir -p "${MONGODB_DUMP_DIRECTORY}/mongodump"
|
then mkdir -p "${MONGODB_DUMP_DIRECTORY}/mongodump"
|
||||||
fi
|
fi
|
||||||
log "Dumping mongo database"
|
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