Geschrieben von Frank Mankel
Kategorie: Armbian

Was möchte ich machen?

Ich habe einen BananaPi mit einem aktuellen Armbian. Am BananaPi hängt eine 1TB Platte. Dieser BananaPi soll nun regelmäßig mittels Restic mein NAS sichern.

Zu Restic habe ich schon ein Artikel verfasst. Restic - Backuptool vorgestellt

 

Voraussetzungen

Wie ich beim ersten Versuch mit Restic gelernt habe, brauchen wir ein aktuelles GO. Das Go was man mit apt-get installieren kann ist zu alt, das können wir nicht einsetzen. Dann werden wir mal das aktuelle installieren.

cd tmp
wget https://storage.googleapis.com/golang/go1.8.3.linux-armv6l.tar.gz
tar -C /usr/local -xzf go1.8.3.linux-armv6l.tar.gz

Damit ist Go in /usr/local installiert.

Damit das System weiß, wo go liegt, muss der Pfad gesetzt werden.

export PATH=$PATH:/usr/local/go/bin

 

Danach kommt bei

go version
go version go1.8.3 linux/arm

So weit, so gut. Den Pfadbefehl muss ich jetzt nur noch dauerhaft einrichten.

nano $HOME/.profile

Das File .profile

# ~/.profile: executed by Bourne-compatible login shells.

if [ "$BASH" ]; then
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
fi

mesg n

export PATH=$PATH:/usr/local/go/bin

 

Danach ist der Pfad dauerhaft eingestellt! Nun kann man auf dem System die aktuelle Version von Go benutzen.

 

Installation Restic

Nun installieren wir Restic. Dazu verweise ich mal auf den ersten Artikel.

Restic - Backuptool vorgestellt

 

root@bananapi:/tmp/restic# restic version
restic 0.7.0 (v0.7.0-16-g04d27ac)
compiled with go1.8.3 on linux/arm

 

Rennt :)

 

Script und Backup-job anlegen!

Wir ergänzen das Script aus dem anderen Artikel um die Mount Funktion. Oder fangen wir mal vorne an, was möchte ich machen?

 

 

Als erstes, ich hab es mal wieder vergessen :( , installiert man nfs-common!

apt-get install nfs-common

 

Das Script:


#!/bin/bash
# Script um meine Dokumente vom NAS regelmäßig zu sichern

# Mounten der NFS Freigabe
mount -t nfs 192.168.3.243:/mnt/nas /media/NAS/

# Repo definieren und PW hinterlegen
export RESTIC_REPOSITORY=/home/backup
export RESTIC_PASSWORD=12345678

#Was soll gesichert werden?
backup_pfad=/media/NAS

#Programm Start
restic -r $RESTIC_REPOSITORY backup $backup_pfad

#NFS Freigabe entfernen
umount -t nfs 192.168.3.243:/mnt/nas /media/NAS/

 

Erklärung:
1. Wir mounten die NFS-Freigabe des NAS nach /media/NAS
2. Mit Restic das Backup erzeugen.
3. Wir entfernen die Freigabe wieder!

 

Mal kurz ein Test ob das Script funktioniert.

backup.png

 

Cronjob anlegen

crontab -e

Dann fügen wir den crontab hinzu.

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
00 23 * * * /backup.sh

Jeden Tag um 23:00 Uhr wird backup.sh ausgeführt.

 

Viel Spaß beim Sichern Eurer Daten. Ein Problem ist bei mir aufgetaucht, was ich bis jetzt nicht lösen konnte. Bei der Sicherung großer Mengen an Daten (500GB) scheint es ein Problem zu geben, diese Jobs sind nie vernünftig beendet worden. Es scheint da ein Problem mit restic zu geben, kann aber auch am begrenzten Speicher des BananaPi's liegen. Kleinere Sicherungen waren kein Problem.