Skip to content

Commit c881d8a

Browse files
committed
Creation of sole feckback repo.
Last commit: 28-12-2020
0 parents  commit c881d8a

File tree

7 files changed

+183
-0
lines changed

7 files changed

+183
-0
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# FECKBACK
2+
A specifically-tailored backup script collection. Works well for my situation. It may also work well for yours!
3+
4+
*Licence* 3BSD. Not GPL because I don't want contributions, but you're free to it!
5+
6+
# Requirements
7+
* Bash
8+
* ssh with keys installed
9+
* tar
10+
* rsync (optional)
11+
12+
## Configuration
13+
Run setup.sh.
14+
15+
Edit `~/.config/feckback.conf` to suit your environment.
16+
17+
Edit `~/.config/feckback.exclude` specify any directories for exclusion.
18+
19+
**Note:** For feckback.exclude, all directories are relative to the root of the backupDir.
20+
This isn't pattern matched, so you'll have to specify each subdirectory for exclusion manually.
21+
22+
### Configuration - multiple jobs
23+
It's possible you may want to have more than one backup job on your system.
24+
25+
In that case, run `./setup.sh <newjob>` to install a new job with that name..
26+
27+
Then, edit `~/.config/feckback.d/<newjob>.conf` and `<newjob>.exclude` for your job.
28+
29+
Call `./feckback.sh <jobname>` and the config and exclude files for that job will be read from `feckback.d`. Then the job will begin.
30+
31+
## Usage
32+
Run `./feckback.sh`. If your hosts are configured correctly, this should work.
33+
34+
## Auxilary Scripts
35+
### syncnas.sh
36+
It's always wise to backup your backups. So, I wrote this script because by Synology NAS couldn't write any data to USB without corrupting the filesystem.
37+
38+
Syncnas should be run on an external headless device such as a RPi. It will sync the contents of the network drive with portable storage, assuming you've ssh access and rsync running.
39+
40+
It uses nohup to continue running after logout.
41+
42+
## Future plans
43+
`backupwin.cmd` - An equivalent in Windows Batch (*not* Bash) to backup and copy Windows files.

backuplx.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
3+
# Feckback: Linux Backup Script
4+
# Author: Lordfeck. Authored: 5/07/2020
5+
6+
function checkFatal {
7+
if [ "$?" -ne "0" ]; then
8+
echo "Failure when $@"
9+
exit 1
10+
fi
11+
}
12+
13+
# Params indicate a jobname, otherwise homedir
14+
if [ ! -n "$1" ]; then
15+
jobname="homedir"
16+
fbConf="${HOME}/.config/feckback.conf"
17+
excludeText="${HOME}/.config/feckback.exclude"
18+
else
19+
jobname="$1"
20+
fbConf="${HOME}/.config/feckback.d/$jobname.conf"
21+
excludeText="${HOME}/.config/feckback.d/$jobname.exclude"
22+
fi
23+
24+
source "$fbConf"
25+
checkFatal "reading config file. Exiting."
26+
27+
28+
if [ ! -e "$excludeText" ]; then
29+
noExclude="1"
30+
else
31+
excludeDirs="$(cat $excludeText | tr '\n' ',')"
32+
fi
33+
34+
: ${toBackup:?"Fatal: Backup source unset."}
35+
: ${destPath:?"Fatal: Backup destination path unset."}
36+
: ${destHost:?"Fatal: Backup destination host unset."}
37+
: ${localDest:?"Fatal: Local destination path unset."}
38+
39+
backupFile="$( hostname )-${USER}-${jobname}.tar.gz"
40+
41+
# Begin main execution... or interpretation?
42+
43+
echo -e "Feckback begins.\nJobname: $jobname\nSrc: $toBackup."
44+
echo "Excluding: $excludeDirs"
45+
echo "Destination Host: $destHost"
46+
echo "Destination Path: $destPath"
47+
echo "Backup File: $backupFile"
48+
echo "Local Destination: $localDest"
49+
50+
echo "Stage 1: Connect to destination and create destination directory, if necessary."
51+
ssh "$destHost" mkdir -pv "$destPath"
52+
checkFatal "connecting to dest. host or creating dest. directory"
53+
54+
sleep 1
55+
echo "Stage 2: Creating the backup in /$localDest/$backupFile"
56+
mkdir -pv "/$localDest/"
57+
checkFatal "creating destination directory"
58+
59+
if [ "$noExclude" = 1 ]; then
60+
tar -czf "/$localDest/$backupFile" "$toBackup"
61+
checkFatal "creating local backup archive"
62+
else
63+
tar -czf "/$localDest/$backupFile" -X "$excludeText" "$toBackup"
64+
checkFatal "creating local backup archive"
65+
fi
66+
67+
sleep 1
68+
echo "Stage 3: Copy backup to destination host."
69+
scp "/$localDest/$backupFile" "$destHost:$destPath"
70+
checkFatal "Copying backup archive to destination."

feckback.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Feckback Backup Config
2+
# Edit then place in ~/.config/feckback.conf
3+
4+
toBackup="$HOME"
5+
6+
destPath="/volume/backups/$(hostname)"
7+
destHost="netdrive"
8+
localDest="/var/tmp"

feckback.exclude

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
music
2+
Downloads
3+
.cache
4+
src_notmine

setup.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
3+
# Feckback Setup Script
4+
# Author: Lordfeck
5+
6+
if [ -n "$1" ]; then
7+
jobname="$1"
8+
fi
9+
10+
readonly confDir="$HOME/.config"
11+
12+
function checkFatal {
13+
if [ "$?" -ne "0" ]; then
14+
echo "$@"
15+
exit 1
16+
fi
17+
}
18+
19+
function copyConf {
20+
local dest="$2"
21+
mkdir -pv "$dest"
22+
23+
if [ -s "$dest/$1.conf" ]; then
24+
echo "$1.conf already exists, skipping copy stage."
25+
else
26+
cp -v "./feckback.conf" "$dest/$1.conf"
27+
checkFatal "installing $1.conf"
28+
fi
29+
30+
if [ -s "$dest/$1.exclude" ]; then
31+
echo "$1.exclude already exists, skipping copy stage."
32+
else
33+
cp -v "./feckback.exclude" "$dest/$1.exclude"
34+
checkFatal "installing $1.conf"
35+
fi
36+
}
37+
38+
# If a param is supplied, use it as jobname. Else only install default.
39+
40+
if [ -n "$jobname" ]; then
41+
echo "Installing new job $jobname to $confDir/feckback.d/$jobname.conf..."
42+
mkdir -pv "$confDir/feckback.d"
43+
checkFatal "Creating feckback.d"
44+
45+
echo "First installing default feckback.conf, if not already present."
46+
copyConf "feckback" "$confDir"
47+
echo "Now installing $jobname"
48+
copyConf "$jobname" "$confDir/feckback.d"
49+
else
50+
copyConf "feckback" "$confDir"
51+
fi
52+
53+
echo "Setup complete."

syncnas.ignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@*

syncnas.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
# Feckback: Quick Rsync wrapper to sync NAS and USB Mirror.
3+
4+
nohup rsync --archive --exclude-from syncnas.ignore --bwlimit=5000 host:/volume1/{Archive,Share} /media/usbdisk/nas/ > rsync.log &

0 commit comments

Comments
 (0)