Skip to content
Permalink
Browse files

Initial commit

  • Loading branch information...
decke committed Jul 23, 2018
0 parents commit 9c00da8e3b07804c104dd4f64f87c55ffb2fda40
Showing with 683 additions and 0 deletions.
  1. +56 −0 LICENSE
  2. +34 −0 Makefile
  3. +82 −0 README.md
  4. +42 −0 lib/base
  5. +87 −0 lib/cmd
  6. +104 −0 lib/config
  7. +205 −0 lib/util
  8. +28 −0 rc.d/ssbt
  9. +45 −0 ssbt
56 LICENSE
@@ -0,0 +1,56 @@
Copyright 2018 Bernhard Froehlich <decke@bluelife.at>
All rights reserved

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


========================================================================

Parts of the code were copied from vm-bhyve under the BSD License:
https://github.com/churchers/vm-bhyve


Copyright (c) 2015-2016, churchers
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,34 @@
#
# ssbt Makefile
#

PREFIX?=/usr/local
BINDIR=$(DESTDIR)$(PREFIX)/sbin
LIBDIR=$(DESTDIR)$(PREFIX)/lib/ssbt
MANDIR=$(DESTDIR)$(PREFIX)/man/man8
RCDIR=$(DESTDIR)$(PREFIX)/etc/rc.d

CP=/bin/cp
INSTALL=/usr/bin/install
MKDIR=/bin/mkdir

PROG=ssbt
MAN=$(PROG).8

install:
$(MKDIR) -p $(BINDIR)
$(INSTALL) -m 544 $(PROG) $(BINDIR)/

$(MKDIR) -p $(LIBDIR)
$(INSTALL) lib/* $(LIBDIR)/

$(MKDIR) -p $(RCDIR)
$(INSTALL) -m 555 rc.d/* $(RCDIR)/

$(MKDIR) -p $(MANDIR)
gzip -fk $(MAN)
$(INSTALL) $(MAN).gz $(MANDIR)/
rm -f -- $(MAN).gz

.MAIN: clean
clean: ;
@@ -0,0 +1,82 @@
## ssbt (Simple Stupid Backup Tool)

You create a backup on your machine and ssbt will periodically
collect and archive it.

* Simple (no database, just filesystem and a config)
* Secure (using chrooted sftp)
* Archive old backups
* First class FreeBSD support


## But why yet another backup solution?

Backups should be simple and reliable to make sure they are as painless as
possible. I know there are a lot of tools out there with fancy webinterfaces,
agents for whatever service you might run, multiuser, cross platform and much
more. You will not find any of those features here.

What you will find is a simple shellscript which will periodically log into
your machines with sftp(1) and pull tar archives from there which get archived.

You can continue to create your backups with tar(1) and be sure those are
archived on your backup master.


## Quick-Start

### Client

A account is needed which will be used by the master to login and fetch the
backups. It is recommended to create a separate account with a separate
SSH certificate. This account can also be limited to only allow sftp to
reduce the risk.

This example assumes that you backup to `/backup/data` but this can be any
directory.

# adduser -d "" -D -s nologin -w no
Username: backup
Full name:
Uid (Leave empty for default):
Login group [backup]:
Login group is backup. Invite backup into other groups? []:
Login class [default]:
Shell (sh csh tcsh nologin) [nologin]:
Home directory [/backup]:
Home directory permissions (Leave empty for default):
Use password-based authentication? [no]:
Lock out the account after creation? [no]:
Username : backup
Password : <disabled>
Full Name :
Uid : 1001
Class :
Groups : backup
Home : /backup
Home Mode :
Shell : /usr/sbin/nologin
Locked : no
OK? (yes/no): yes
adduser: INFO: Successfully added (backup) to the user database.
Add another user? (yes/no): no
Goodbye!

# mkdir -m 0755 /backup
# install -d -m 0700 -g backup -o backup /backup/.ssh
# install -d -m 0700 -g backup -o backup /backup/data

# install -m 0400 -g backup -o backup /dev/null /backup/.ssh/authorized_keys
# echo "...your-public-key-here..." > /backup/.ssh/autorized_keys

# printf "\nMatch User backup\n" >> /etc/ssh/sshd_config
# printf "\tChrootDirectory %%h\n" >> /etc/ssh/sshd_config
# printf "\tForceCommand internal-sftp\n" >> /etc/ssh/sshd_config
# printf "\tX11Forwarding no" >> /etc/ssh/sshd_config

# /etc/rc.d/sshd reload


### Backup master


@@ -0,0 +1,42 @@
#!/bin/sh
#
# Copyright 2018 Bernhard Froehlich <decke@bluelife.at>
# All rights reserved
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

VERSION=0.1

. /etc/rc.subr
load_rc_config "ssbt"

# create directories as needed
[ ! -d "${ssbt_dir}" ] && util::err "\$ssbt_dir has not been configured or is not a valid directory"
[ ! -d "${ssbt_dir}/.config" ] && mkdir "${ssbt_dir}/.config"

# load core configuration
config::core::load

# run the requested command
cmd::parse "$@"
87 lib/cmd
@@ -0,0 +1,87 @@
#!/bin/sh
#-------------------------------------------------------------------------+
# Copyright (C) 2016 Matt Churchyard (churchers@gmail.com)
# All rights reserved
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted providing that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

CMD_VALID_LIST="cron,pull,status,usage,version"

# cmd: ssbt ...
#
# process the command line to see which function is requested
#
# @param string _cmd the command right after 'ssbt '
#
cmd::parse(){
local _cmd

# try to find a matching command
cmd::find "_cmd" "$1" "${CMD_VALID_LIST}" || util::usage
shift

case "${_cmd}" in
cron) core::cron "$@" ;;
pull) core::pull "$@" ;;
status) core::status "$@" ;;
usage) util::usage ;;
version) util::version && exit ;;
*) util::err "unknown command '${_user_cmd}'. please run 'ssbt usage' or view the manpage for help" ;;
esac
}

# try to match part of a command name against a list of valid commands
# if we find more than one match we return an error
# if we only get one match, return the full command name
#
# @param string _var variable to put full command name into
# @param string _user_cmd the value provided by the user
# @param string _valid comma-separated list of valid choices
# @return success if we find one match
#
cmd::find(){
local _var="$1"
local _user_cmd="$2"
local _valid="$3"
local _opt _choice _found=""
local IFS=","

[ -n "${_user_cmd}" ] || util::err "no command specified"

for _opt in ${_valid}; do
# exact match?
if [ "${_user_cmd}" = "${_opt}" ]; then
setvar "${_var}" "${_opt}"
return 0
fi

if echo "${_opt}" | grep -iqs "^${_user_cmd}"; then
[ -n "${_found}" ] && util::err "ambiguous command '${_user_cmd}'"

_found=1
_choice="${_opt}"
fi
done

[ -z "${_found}" ] && return 1
setvar "${_var}" "${_choice}"
}

0 comments on commit 9c00da8

Please sign in to comment.
You can’t perform that action at this time.