Added v0.1 of restic_backups.sh
This commit is contained in:
parent
c6c0e8c1b1
commit
2622223ee4
72
README.md
72
README.md
|
@ -2,36 +2,62 @@
|
||||||
|
|
||||||
My personal collection of handy scripts. mostly bash.
|
My personal collection of handy scripts. mostly bash.
|
||||||
|
|
||||||
Content:
|
- [restic_backup.sh](#restic_backup.sh)
|
||||||
|
|
||||||
- [setup_zsh.sh](#setup_zsh.sh)
|
- [setup_zsh.sh](#setup_zsh.sh)
|
||||||
- [healthchecks](#healthchecks)
|
|
||||||
|
## restic_backup.sh
|
||||||
|
|
||||||
|
> This script is my very simple take on how to perform restic backups.
|
||||||
|
|
||||||
|
First you need to download the script from this Git repository. I usually just put it in root's home.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Download
|
||||||
|
sudo curl -o /root/restic_backup.sh https://git.socialnerds.org/david/scripts/raw/branch/main/restic_backup.sh
|
||||||
|
sudo chmod +x /root/restic_backup.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
In the config section at the top of the script you can change various options to your liking.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# **** CONFIG ****
|
||||||
|
PASSWORD="/root/.restic-password"
|
||||||
|
REPO="sftp:<remote-server>:/path/to/repository"
|
||||||
|
KEEP=30
|
||||||
|
BIN="/usr/bin/restic"
|
||||||
|
OPTIONS="-p $PASSWORD -r $REPO -q"
|
||||||
|
```
|
||||||
|
|
||||||
|
You can run `restic_backup.sh` directly from the command line
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Usage
|
||||||
|
/root/restic_backup.sh /local/path <additional flags for the backup subcommand>
|
||||||
|
|
||||||
|
# Example
|
||||||
|
/root/restic_backup.sh /home -x -e ./.snapshots
|
||||||
|
```
|
||||||
|
|
||||||
|
or using cron.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Cronjob
|
||||||
|
47 0 * * * /root/restic_backup.sh /home
|
||||||
|
|
||||||
|
# Cronjob (with healthchecks notification)
|
||||||
|
47 0 * * * /root/restic_backup.sh /home && curl -fsS -m 10 --retry 5 -o /dev/null https://checks.socialnerds.org/ping/fb721aec-5179-42c3-3455-4fd2ff39ii55
|
||||||
|
```
|
||||||
|
|
||||||
|
Happy backuping! :-)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## setup_zsh.sh
|
## setup_zsh.sh
|
||||||
|
|
||||||
One-line installer for zsh, oh-my-zsh and various zsh plugins.
|
> One-line installer for zsh, oh-my-zsh and various zsh plugins.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -fsSL https://socialg.it/david/scripts/raw/master/setup_zsh.sh | bash
|
curl -fsSL https://socialg.it/david/scripts/raw/master/setup_zsh.sh | bash
|
||||||
```
|
```
|
||||||
|
|
||||||
It is still highly experimental and will probably fail on your system.
|
It is still highly experimental and will probably fail on your system.
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## healthchecks
|
|
||||||
|
|
||||||
A collection of scripts for monitoring various things with [healthchecks.io](https://healthchecks.io).
|
|
||||||
My personal healthchecks instance runs at [checks.socialnerds.org](https://checks.socialnerds.org) though only the `/ping` endpoint is publicly available. The rest of the interface is limited to internal networks.
|
|
||||||
All healthchecks reside in their own repository at [socialg.it/david/healthchecks](https://socialg.it/david/healthchecks).
|
|
||||||
|
|
||||||
| script | purpose |
|
|
||||||
| :------------ | :--------------------------------------------------------------- |
|
|
||||||
| system.sh | Fire if load, memory or diskusage hits the configured threshold |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## setup_snmpd.sh
|
|
||||||
|
|
||||||
`setup_snmpd.sh` installs and configures the snmp daemon to be used with [libreNMS](https://librenms.org).
|
|
||||||
Supported operating systems are Ubuntu, Debian, Raspbian and Archlinux.
|
|
||||||
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# name: restic_backup.sh
|
||||||
|
# version: 0.1
|
||||||
|
# author: david@socialnerds.org
|
||||||
|
# license: MIT
|
||||||
|
# description: a simple script to automate the restic backup utility.
|
||||||
|
# i created this for my personal use, though you are very
|
||||||
|
# welcome reuse and improve.
|
||||||
|
|
||||||
|
|
||||||
|
# **** CONFIG ****
|
||||||
|
PASSWORD="/root/.restic-password"
|
||||||
|
REPO="sftp:jupiter.socialner.ds:/srv/storage/restic-repositories/hood"
|
||||||
|
KEEP=30
|
||||||
|
BIN="/usr/bin/restic"
|
||||||
|
OPTIONS="-p $PASSWORD -r $REPO -q"
|
||||||
|
|
||||||
|
|
||||||
|
# **** START ****
|
||||||
|
CMD="$BIN -p $PASSWORD -r $REPO $OPTIONS"
|
||||||
|
|
||||||
|
#TODO: check for elevated privileges
|
||||||
|
|
||||||
|
# Generate a new password file if it is missing or empty
|
||||||
|
if [ ! -s $PASSWORD ]; then
|
||||||
|
#echo "error: Password file is empty or does not exist. [$PASSWORD]"
|
||||||
|
#exit 1
|
||||||
|
tr -cd '[:alnum:]' < /dev/urandom | fold -w32 | head -n1 > $PASSWORD
|
||||||
|
chmod 600 $PASSWORD
|
||||||
|
echo "warning: New password file generated since it does not exist or is empty. [$PASSWORD]"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Initialize a new repo if the repo url has no config file
|
||||||
|
$CMD snapshots >/dev/null 2>&1
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
$CMD init >/dev/null 2>&1
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "error: A problem occured while creating a new repository. [$REPO]"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "warning: New repository initialized. [$REPO]"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Run the restic repository check
|
||||||
|
$CMD check > /dev/null
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "error: Repository check failed. [$REPO]"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# First option must be a readable folder/file
|
||||||
|
if [ $1 ]; then
|
||||||
|
if [ -r $1 ]; then
|
||||||
|
LOCAL=$1
|
||||||
|
else
|
||||||
|
echo "error: The path given does not seem to be readable. [$1]"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "error: Local path must be given as an option."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Run the actual backup
|
||||||
|
$CMD backup ${@:2} $LOCAL > /dev/null
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "error: Something went wrong while running backup. [$LOCAL]"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Delete old snapshots
|
||||||
|
$CMD forget --keep-last $KEEP --path $LOCAL --prune > /dev/null
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "error: Something went wrong while deleting old snapshots. [$LOCAL]"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# **** END ****
|
||||||
|
exit 0
|
Loading…
Reference in New Issue