├── .github └── workflows │ └── main.yml ├── COPYING.txt ├── Makefile ├── docs ├── readme.adoc ├── readme.md ├── snebu-client-backup.1 ├── snebu-client-backup_1.adoc ├── snebu-client-listbackups.1 ├── snebu-client-listbackups_1.adoc ├── snebu-client-plugin.5 ├── snebu-client-plugin_5.adoc ├── snebu-client-restore.1 ├── snebu-client-restore_1.adoc ├── snebu-client-validate.1 ├── snebu-client-validate_1.adoc ├── snebu-client.1 ├── snebu-client.conf.5 ├── snebu-client.conf_5.adoc ├── snebu-client_1.adoc ├── snebu-concepts.adoc ├── snebu-expire.1 ├── snebu-expire_1.adoc ├── snebu-intro.adoc ├── snebu-listbackups.1 ├── snebu-listbackups_1.adoc ├── snebu-newbackup.1 ├── snebu-newbackup_1.adoc ├── snebu-permissions.1 ├── snebu-permissions_1.adoc ├── snebu-purge.1 ├── snebu-purge_1.adoc ├── snebu-quickstart.adoc ├── snebu-reference.adoc ├── snebu-restore.1 ├── snebu-restore_1.adoc ├── snebu-submitfiles.1 ├── snebu-submitfiles_1.adoc ├── snebu.1 ├── snebu.adoc ├── snebu_1.adoc ├── tarcrypt.1 └── tarcrypt_1.adoc ├── readme.md ├── snebu-client ├── snebu-client-db-plugin-template ├── snebu-expire-purge.c ├── snebu-listbackups.c ├── snebu-main.c ├── snebu-newbackup.c ├── snebu-permissions.c ├── snebu-restore.c ├── snebu-submitfiles.c ├── snebu.conf ├── snebu_update_db.sql ├── tarcrypt.c ├── tarcrypt.txt ├── tarlib.c └── tarlib.h /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Test Build 3 | 4 | # Use string "on" as bare "on" converts to a truthy value, causing 5 | # Code Inspector validation to fail. 6 | "on": 7 | - push 8 | - pull_request 9 | 10 | jobs: 11 | build: 12 | 13 | runs-on: ubuntu-20.04 14 | 15 | steps: 16 | 17 | - uses: actions/checkout@v2 18 | 19 | - name: install dependencies 20 | run: sudo apt-get install -y liblzo2-dev libsqlite3-dev libssl-dev 21 | 22 | - name: make 23 | run: make 24 | 25 | - name: make install 26 | run: sudo make install 27 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | PKGNAME=snebu 3 | PROGS=snebu tarcrypt 4 | SCRIPTS=snebu-client 5 | CONFIGS=snebu.conf 6 | SOWNER=snebu 7 | SGROUP=snebu 8 | MAN1=snebu.1 snebu-client.1 snebu-client-backup.1 snebu-client-listbackups.1 snebu-client-restore.1 snebu-client-validate.1 snebu-expire.1 snebu-listbackups.1 snebu-newbackup.1 snebu-permissions.1 snebu-purge.1 snebu-restore.1 snebu-submitfiles.1 tarcrypt.1 9 | MAN5=snebu-client.conf.5 snebu-client-plugin.5 10 | DOC=readme.md snebu*.adoc 11 | LICENSE=COPYING.txt 12 | PREFIX=/usr/local 13 | DATADIR=${PREFIX}/share 14 | BINDIR=$(PREFIX)/bin 15 | MANDIR=$(DATADIR)/man 16 | DOCDIR=$(DATADIR)/doc 17 | ETCDIR=/etc 18 | all: $(PROGS) 19 | %.o: %.c 20 | $(CC) -D_GNU_SOURCE -std=c99 -c $< -o $@ -Wall $(CFLAGS) 21 | tarlib.o: tarlib.h 22 | tarcrypt.o: tarlib.h 23 | snebu-submitfiles.o: tarlib.h 24 | snebu-restore.o: tarlib.h 25 | 26 | snebu: snebu-main.o snebu-newbackup.o tarlib.o snebu-submitfiles.o snebu-restore.o snebu-listbackups.o snebu-expire-purge.o snebu-permissions.o 27 | $(CC) -D_GNU_SOURCE -std=c99 $^ -o $@ -l sqlite3 -l crypto -l lzo2 -Wall $(CFLAGS) $(LDFLAGS) 28 | tarcrypt: tarcrypt.o tarlib.o 29 | $(CC) -D_GNU_SOURCE -std=c99 $^ -o $@ -l crypto -l ssl -l lzo2 -Wall $(CFLAGS) $(LDFLAGS) 30 | install: $(PROGS) $(SCRIPTS) $(CONFIGS) 31 | mkdir -p $(DESTDIR)$(BINDIR) 32 | mkdir -p $(DESTDIR)$(ETCDIR) 33 | mkdir -p $(DESTDIR)$(MANDIR)/man1 34 | mkdir -p $(DESTDIR)$(MANDIR)/man5 35 | mkdir -p $(DESTDIR)$(DOCDIR)/$(PKGNAME) 36 | install -p -m 755 $(PROGS) $(SCRIPTS) $(DESTDIR)$(BINDIR)/ 37 | install -p -m 644 $(CONFIGS) $(DESTDIR)$(ETCDIR)/ 38 | install -p -m 644 $(addprefix docs/,$(MAN1)) $(DESTDIR)$(MANDIR)/man1 39 | install -p -m 644 $(addprefix docs/,$(MAN5)) $(DESTDIR)$(MANDIR)/man5 40 | install -p -m 644 $(addprefix docs/,$(DOC)) $(DESTDIR)$(DOCDIR)/$(PKGNAME) 41 | 42 | clean: 43 | rm -f $(PROGS) snebu-main.o snebu-newbackup.o tarlib.o snebu-submitfiles.o snebu-restore.o snebu-listbackups.o snebu-expire-purge.o snebu-permissions.o tarcrypt.o 44 | 45 | -------------------------------------------------------------------------------- /docs/snebu-client-backup.1: -------------------------------------------------------------------------------- 1 | .TH SNEBU-CLIENT-BACKUP "1" "December 2020" "snebu-client-backup" "User Commands" 2 | .na 3 | .SH NAME 4 | snebu-client backup \- Initiates a backup 5 | .SH SYNOPSIS 6 | .B snebu-client 7 | \fBbackup \/\fR 8 | [ \fB-n\fR \fIbackupname\fR ] 9 | [ \fB-d\fR \fIdatestamp\fR ] 10 | [ \fB-r\fR \fIschedule\fR ] 11 | [ \fIfile\-list\fR ] 12 | .SH DESCRIPTION 13 | Initiates a system backup. 14 | By default, it will back up the local host to a local snebu install. 15 | You can also use this command to back up to a remote backup server, 16 | back up a remote host to either a local snebu installation, 17 | or back up a remote host to another remote backup server, 18 | depending on which options are chosen. 19 | .SH OPTIONS 20 | .TP 21 | \fB\-c\fR, \fB\-\-config\fR \fIconfig_file\fR 22 | Name of the configuration file. Default is 23 | \fI/etc/snebu\-client.conf\/\fP. 24 | .TP 25 | \fB\-n\fR, \fB\-\-name\fR \fIbackupname\fR 26 | Name of the backup. Usually set to the server 27 | name that you are backing up. 28 | .TP 29 | \fB\-d\fR, \fB\-\-date\fR \fIdatestamp\fR 30 | Date stamp for this backup set. The format is in 31 | time_t format, sames as the output of the "date\~+%s" command. 32 | .TP 33 | \fB\-r\fR, \fB\-\-retention\fR \fIschedule\fR 34 | Retention schedule for this backup set. Typical 35 | values are "daily", "weekly", "monthly", "yearly". 36 | .TP 37 | \fB\-k\fR, \fB\-\-encryption\-key\fR \fIkeyfile\fR 38 | Turns on encryption, and specifies encryption 39 | key location. May be specified more than once to 40 | encrypt with multiple keys. 41 | .IP 42 | The program "tarcrypt" needs to be present on the 43 | client for this option. Keys are generated with 44 | the command: 45 | .IP 46 | \fBtarcrypt genkey \-f\fR \fIkeyfile\fR [ \fB-c\fR \fIcomment\fR ] 47 | .TP 48 | \fB\-C\fR, \fB\-\-changedir\fR \fIpath\fR 49 | Changes to the given directory path before backing up. 50 | .TP 51 | \fB\-\-graft\fR \fI/path/name/\fR\fB=\fR\fI/new/name/\fR 52 | Re\-write path names beginning with "\fI/path/name/\fR" 53 | to "\fI/new/name/\fR" 54 | .TP 55 | \fB\-f\fR, \fB\-\-force\-full\fR 56 | Force a full backup 57 | .TP 58 | \fB\-\-remote\-client\fR \fIhostname\fR 59 | Host name / IP address of remote host. Used to 60 | backup a remote host to local backup server. 61 | .TP 62 | \fB\-\-remote\-user\fR \fIuserid\fR 63 | User ID for remote remote\-client. Defaults to 64 | root. 65 | .TP 66 | \fB\-\-sudo\fR \fIuserid\fR 67 | Initial login User ID for remote remote\-client. 68 | This ID uses sudo to switch to remote\-user once 69 | logged in. 70 | .TP 71 | \fB\-\-backup\-server\fR \fIhostname\fR 72 | Host name / IP address of backup server. Used to 73 | backup to a remote server. 74 | .TP 75 | \fB\-\-backup\-user\fR \fIuserid\fR 76 | User ID for remote backup\-server. 77 | .TP 78 | \fB\-\-plugin\fR \fIscriptname\fR 79 | Specifies an optional plug in script. Usually 80 | used to perform database\-specific operations 81 | (such as enabling hot backup mode) for systems 82 | with a DB installed. 83 | .TP 84 | [ \fIfile\-list\fR ] 85 | List of files to backup. 86 | Overrides default specified in snebu-client.conf file. 87 | .SH "SEE ALSO" 88 | \fBtarcrypt\fR(1) 89 | -------------------------------------------------------------------------------- /docs/snebu-client-backup_1.adoc: -------------------------------------------------------------------------------- 1 | === snebu-client-backup(1) - Initiates a backup 2 | 3 | 4 | ---- 5 | snebu-client backup [ -n backupname ] [ -d datestamp ] [ -r schedule ] [ file-list ] 6 | ---- 7 | 8 | ==== Description 9 | 10 | Initiates a system backup. 11 | By default, it will back up the local host to a local snebu install. 12 | You can also use this command to back up to a remote backup server, 13 | back up a remote host to either a local snebu installation, 14 | or back up a remote host to another remote backup server, 15 | depending on which options are chosen. 16 | 17 | ==== Options 18 | 19 | 20 | *-c*, *--config* _config_file_:: 21 | Name of the configuration file. Default is 22 | _/etc/snebu-client.conf_. 23 | 24 | *-n*, *--name* _backupname_:: 25 | Name of the backup. Usually set to the server 26 | name that you are backing up. 27 | 28 | *-d*, *--date* _datestamp_:: 29 | Date stamp for this backup set. The format is in 30 | time_t format, sames as the output of the "date +%s" command. 31 | 32 | *-r*, *--retention* _schedule_:: 33 | Retention schedule for this backup set. Typical 34 | values are "daily", "weekly", "monthly", "yearly". 35 | 36 | *-k*, *--encryption-key* _keyfile_:: 37 | Turns on encryption, and specifies encryption 38 | key location. May be specified more than once to 39 | encrypt with multiple keys. 40 | * The program "tarcrypt" needs to be present on the 41 | client for this option. Keys are generated with 42 | the command: 43 | * *tarcrypt genkey -f* _keyfile_ [ *-c* _comment_ ] 44 | 45 | *-C*, *--changedir* _path_:: 46 | Changes to the given directory path before backing up. 47 | 48 | *--graft* _/path/name/_*=*_/new/name/_:: 49 | Re-write path names beginning with "_/path/name/_" 50 | to "_/new/name/_" 51 | 52 | *-f*, *--force-full*:: 53 | Force a full backup 54 | 55 | *--remote-client* _hostname_:: 56 | Host name / IP address of remote host. Used to 57 | backup a remote host to local backup server. 58 | 59 | *--remote-user* _userid_:: 60 | User ID for remote remote-client. Defaults to 61 | root. 62 | 63 | *--sudo* _userid_:: 64 | Initial login User ID for remote remote-client. 65 | This ID uses sudo to switch to remote-user once 66 | logged in. 67 | 68 | *--backup-server* _hostname_:: 69 | Host name / IP address of backup server. Used to 70 | backup to a remote server. 71 | 72 | *--backup-user* _userid_:: 73 | User ID for remote backup-server. 74 | 75 | *--plugin* _scriptname_:: 76 | Specifies an optional plug in script. Usually 77 | used to perform database-specific operations 78 | (such as enabling hot backup mode) for systems 79 | with a DB installed. 80 | 81 | [ _file-list_ ]:: 82 | List of files to backup. 83 | Overrides default specified in snebu-client.conf file. 84 | 85 | ==== See Also 86 | 87 | *tarcrypt*(1) 88 | -------------------------------------------------------------------------------- /docs/snebu-client-listbackups.1: -------------------------------------------------------------------------------- 1 | .TH SNEBU-CLIENT-LISTBACKUPS "1" "December 2020" "snebu-client-listbackups" "User Commands" 2 | .na 3 | .SH NAME 4 | snebu-client listbackups \- Lists backed up systems, backup sets, and file names 5 | .SH SYNOPSIS 6 | .B snebu-client 7 | \fBlistbackups\fR 8 | [ \fB-n\fR \fIhostname\fR [ \fB-d\fR \fIdatestamp\fR ]] 9 | [ \fIfile_list\fR... ] 10 | .SH DESCRIPTION 11 | With no arguments specified, "listbackups" will return a list of all 12 | systems that are contained in the backup catalog. Otherwise, when 13 | specifying the \fB\-n\fR parameter, a list of backup sets for that host is 14 | returned. 15 | .SH OPTIONS 16 | .TP 17 | \fB\-c\fR, \fB\-\-config\fR \fIconfig_file\fR 18 | Name of the configuration file. 19 | Default is \fI/etc/snebu\-client.conf\/\fP. 20 | .TP 21 | \fB\-n\fR, \fB\-\-name\fR \fIbackupname\fR 22 | Name of the backup. 23 | Usually set to the server name that you are backing up. 24 | .TP 25 | \fB\-d\fR, \fB\-\-date\fR \fIdatestamp\fR 26 | Date stamp for this backup set. 27 | The format is in \fItime_t\fR format, 28 | sames as the output of the "date\~+%s" command. 29 | .TP 30 | [ \fIfile\-list\fR ] 31 | List of files to restore. Defaults to all. 32 | -------------------------------------------------------------------------------- /docs/snebu-client-listbackups_1.adoc: -------------------------------------------------------------------------------- 1 | === snebu-client-listbackups(1) - Lists backed up systems, backup sets, and file names 2 | 3 | 4 | ---- 5 | snebu-client listbackups [ -n hostname [ -d datestamp ]] [ file_list... ] 6 | ---- 7 | 8 | ==== Description 9 | 10 | With no arguments specified, "listbackups" will return a list of all 11 | systems that are contained in the backup catalog. Otherwise, when 12 | specifying the *-n* parameter, a list of backup sets for that host is 13 | returned. 14 | 15 | ==== Options 16 | 17 | 18 | *-c*, *--config* _config_file_:: 19 | Name of the configuration file. 20 | Default is _/etc/snebu-client.conf_. 21 | 22 | *-n*, *--name* _backupname_:: 23 | Name of the backup. 24 | Usually set to the server name that you are backing up. 25 | 26 | *-d*, *--date* _datestamp_:: 27 | Date stamp for this backup set. 28 | The format is in _time_t_ format, 29 | sames as the output of the "date +%s" command. 30 | 31 | [ _file-list_ ]:: 32 | List of files to restore. Defaults to all. 33 | -------------------------------------------------------------------------------- /docs/snebu-client-plugin.5: -------------------------------------------------------------------------------- 1 | .TH SNEBU-CLIENT-PLUGIN "5" "December 2020" "snebu-client-plugin" "File Formats" 2 | .na 3 | .SH NAME 4 | snebu-client plugins - Defines pre-backup and post-backup scripts to run on a client. 5 | .SH DESCRIPTION 6 | Specifying the \fB--plugin\fR argument when executing a snebu-client backup operation will cause the specified plugin script to be incorporated into the backup process. The plugin script defines at least two shell script functions -- \fBpluginpref()\fR, which executes prior to the backup, and \fBpluginpostf()\fR which executes after the backup has completed. Two associated variables, \fBpluginpre\fR and \fBpluginpost\fR, contain the names of these two functions (so the functions themselves can be named anything, as long as the variables point to them). 7 | 8 | This allows performing operations such as mounting a file system snapshot prior to a backup and removing the snapshot afterwards, or placing a database in hot backup mode at the beginning of the backup. In the case of backing up a database, often times the backup will need to be completed in multiple stages -- place the DB in hot backup mode, gather a list of database files, back them up, take the DB out of hot backup mode, gather a list of files containing transaction logs that were created during the backup, and finally backing up those files. 9 | 10 | To facilitate these type of backup steps, the \fBpluginpre\fR function can save the contents of the file include/exclude variables \fBINCLUDE\fR, \fBEXCLUDE\fR, and \fBEXCLUDEMATCH\fR. Then set the variable \fBbkrepeat=1\fR, along with setting any other housekeeping variables used inside the plugin script. Once it has completed the last stage, it can then restore the include/exclude variables, let the rest of the backup process continue, and then set \fBbkrepeat=0\fR to finish off the backup. 11 | 12 | Note that the plugin runs on the same host that is running the snebu-client script. So if you are doing \fIpush\fR backups from a client to a server, it will function as expected. But if you are doing \fIpull\fR based backups (running snebu-client from the backup server), then be sure to have the pre and post functions perform their actions on the target server (referencing the \fBclientname\fR and \fIrmtuser\fR variables as appropriate). Feel free to use the \fBrpcsh()\fR function defined in snebu-client (see function definition for brief description and usage). 13 | .SS Functions and Variables 14 | .TP 15 | \fBpluginpref()\fR 16 | Shell script code containing pre-backup procedures. 17 | .PP 18 | .TP 19 | \fBpluginpostf()\fR 20 | Shell script code containing post-backup procedures. 21 | .PP 22 | .TP 23 | \fBpluginpre\fR 24 | Variable containing name of pluginpre function 25 | .PP 26 | .TP 27 | \fBpluginpost\fR 28 | Variable containing name of pluginpost function 29 | .PP 30 | .PP 31 | .TP 32 | \fBbkrepeat\fR 33 | Set bkrepeat=1 to repeat the backup with modifications to the include/exclude list. Every time the backup repeats, the backup set is amended with the new file set. 34 | .PP 35 | .TP 36 | \fBINCLUDE\fR 37 | Shell array containing file include list (see \fBsnebu-client.conf(5)\fR) 38 | .PP 39 | .TP 40 | \fBEXCLUDE\fR 41 | Shell array containing file exclude list (see \fBsnebu-client.conf(5)\fR) 42 | .PP 43 | .TP 44 | \fBEXCLUDEMATCH\fR 45 | Shell array containing file exclude file pattern list (see \fBsnebu-client.conf(5)\fR) 46 | 47 | .SH EXAMPLES 48 | The following is a template that can be used when backing up a server containing a database. In this case, the include/exclude list initially includes files to back up the entire server. So this script does a hot backup of the database first, then adds to the exclude list the dbf files that were backed up initially, and then backs up the rest of the system. 49 | 50 | The Since these functions get called at various times from the snebu-client script, the order of the various code fragments can become a bit confusing. Pay attention to the "(Step x)" labels for the actual execution order in each fragment. 51 | 52 | .nf 53 | ### Snebu backup plugin template for databases 54 | [ -z "${verbose}" ] && verbose=0 55 | [ "${verbose}" -gt 0 ] && echo "Executing client plugin template" >&2 56 | 57 | pluginpre=pluginpref 58 | pluginpost=pluginpostf 59 | # Initialize an internal housekeeping variable 60 | # (Step 0) 61 | dbstage=0 62 | 63 | # Define the pre-backup script 64 | pluginpref() { 65 | [ "${verbose}" -gt 0 ] && 66 | echo "Executing client plugin pre script" >&2 67 | # Stage 0 => haven't backed up the DB yet 68 | if [ "${dbstage}" = 0 ] 69 | then 70 | # (Step 1) 71 | # Save the current include/exclude list 72 | OLD_INCLUDE=( "${INCLUDE[@]}" ) 73 | OLD_EXCLUDE=( "${EXCLUDE[@]}" ) 74 | OLD_EXCLUDEMATCH=( "${EXCLUDEMATCH[@]}" ) 75 | 76 | # Zero out exclude list 77 | EXCLUDE=( ) 78 | EXCLUDEMATCH=( ) 79 | 80 | # Set the include list to include database files 81 | DBF_FILES=( "$( 82 | # Function to list database filenames to standard output 83 | print_dbf_filenames 84 | )" ) 85 | INCLUDE=( "${DBF_FILES[@]}" ) 86 | 87 | # Place DB in hot backup mode 88 | begin_db_backup 89 | 90 | # After this, snebu-client-backup takes over and backs up 91 | # the above set include list. Then control jumps to 92 | # pluginpost() with dbstage still set to 0 93 | elif [ "${dbstage}" = 1 ] 94 | then 95 | # (Step 3) 96 | DBF_LOG_FILES=( "$( 97 | # Function to list archived transaction logs 98 | print_dbf_log_filenames 99 | )" ) 100 | INCLUDE=( "${DBF_LOG_FILES[@]}" ) 101 | 102 | # Back to the backup with the new include list, then 103 | # off to pluginpost again with dbstage set to 1 104 | fi 105 | } 106 | 107 | pluginpostf() { 108 | [ "${verbose}" -gt 0 ] && echo "client plugin post" >&2 109 | if [ "${dbstage}" = 0 ] 110 | then 111 | # (Step 2) 112 | # Take DB out of hot backup mode 113 | end_db_backup 114 | 115 | # Define the next stage, and repeat the backup 116 | dbstage=1 117 | bkrepeat=1 118 | 119 | # Now control jumps back to pluginpre() with dbstage=1 120 | elif [ "${dbstage}" = 1 ] 121 | then 122 | # (Step 4) 123 | # Restore the original include/exclude list, with the 124 | # database files added to the exclude list. 125 | INCLUDE=( "${OLD_INCLUDE[@]}" ) 126 | EXCLUDE=( "${OLD_EXCLUDE[@]}" "${DBF_FILES[@]}" \\ 127 | "${DBF_LOG_FILES[@]}" ) 128 | EXCLUDEMATCH=( "${OLD_EXCLUDEMATCH[@]}" ) 129 | 130 | # Define the next stage, and repeat the backup 131 | dbstage=2 132 | bkrepeat=1 133 | 134 | # Control jumps back to pluginpre(), however no more pre- 135 | # processing is needed for stage 2, so the backup begins 136 | # again with the original client include/exclude (plus the 137 | # above database files added to the exclude). 138 | elif [ "${dbstage}" = 2 ] 139 | then 140 | # (Step 5) 141 | # Break the cycle, backup is completed for this host. 142 | bkrepeat=0 143 | fi 144 | } 145 | 146 | # Also, don't forget to fill in the functions referenced above: 147 | 148 | begin_db_backup() { 149 | [ "${verbose}" -gt 0 ] && echo "Begin DB backup" >&2 150 | ### Steps to place DB in hot backup mode 151 | ### Make sure to execute these on the target host being backed 152 | ### up if running from the backup server (in pull mode) 153 | } 154 | 155 | end_db_backup() { 156 | [ "${verbose}" -gt 0 ] && echo "End DB backup" >&2 157 | ### Steps to DB out of hot backup mode 158 | ### Make sure to execute these on the target host being backed 159 | ### up if running from the backup server (in pull mode) 160 | } 161 | 162 | print_dbf_filenames() { 163 | [ "${verbose}" -gt 0 ] && echo "Generating DBF filenames" >&2 164 | ### Output list of dbf file names 165 | ### Make sure to execute these on the target host being backed 166 | ### up if running from the backup server (in pull mode) 167 | } 168 | 169 | print_dbf_log_filenames() { 170 | [ "${verbose}" -gt 0 ] && echo "Generating DBF log filenames" >&2 171 | ### Output list of archived transaction log file names 172 | ### Make sure to execute these on the target host being backed 173 | ### up if running from the backup server (in pull mode) 174 | } 175 | 176 | .fi 177 | .PP 178 | -------------------------------------------------------------------------------- /docs/snebu-client-plugin_5.adoc: -------------------------------------------------------------------------------- 1 | === snebu-client-plugin(5) - Defines pre-backup and post-backup scripts to run on a client. 2 | 3 | 4 | ==== Description 5 | 6 | Specifying the *--plugin* argument when executing a snebu-client backup operation will cause the specified plugin script to be incorporated into the backup process. The plugin script defines at least two shell script functions -- *pluginpref()*, which executes prior to the backup, and *pluginpostf()* which executes after the backup has completed. Two associated variables, *pluginpre* and *pluginpost*, contain the names of these two functions (so the functions themselves can be named anything, as long as the variables point to them). 7 | 8 | This allows performing operations such as mounting a file system snapshot prior to a backup and removing the snapshot afterwards, or placing a database in hot backup mode at the beginning of the backup. In the case of backing up a database, often times the backup will need to be completed in multiple stages -- place the DB in hot backup mode, gather a list of database files, back them up, take the DB out of hot backup mode, gather a list of files containing transaction logs that were created during the backup, and finally backing up those files. 9 | 10 | To facilitate these type of backup steps, the *pluginpre* function can save the contents of the file include/exclude variables *INCLUDE*, *EXCLUDE*, and *EXCLUDEMATCH*. Then set the variable *bkrepeat=1*, along with setting any other housekeeping variables used inside the plugin script. Once it has completed the last stage, it can then restore the include/exclude variables, let the rest of the backup process continue, and then set *bkrepeat=0* to finish off the backup. 11 | 12 | Note that the plugin runs on the same host that is running the snebu-client script. So if you are doing _push_ backups from a client to a server, it will function as expected. But if you are doing _pull_ based backups (running snebu-client from the backup server), then be sure to have the pre and post functions perform their actions on the target server (referencing the *clientname* and _rmtuser_ variables as appropriate). Feel free to use the *rpcsh()* function defined in snebu-client (see function definition for brief description and usage). 13 | 14 | [discrete] 15 | ==== Functions and Variables 16 | 17 | 18 | *pluginpref()*:: 19 | Shell script code containing pre-backup procedures. 20 | 21 | *pluginpostf()*:: 22 | Shell script code containing post-backup procedures. 23 | 24 | *pluginpre*:: 25 | Variable containing name of pluginpre function 26 | 27 | *pluginpost*:: 28 | Variable containing name of pluginpost function 29 | 30 | *bkrepeat*:: 31 | Set bkrepeat=1 to repeat the backup with modifications to the include/exclude list. Every time the backup repeats, the backup set is amended with the new file set. 32 | 33 | *INCLUDE*:: 34 | Shell array containing file include list (see *snebu-client.conf(5)*) 35 | 36 | *EXCLUDE*:: 37 | Shell array containing file exclude list (see *snebu-client.conf(5)*) 38 | 39 | *EXCLUDEMATCH*:: 40 | Shell array containing file exclude file pattern list (see *snebu-client.conf(5)*) 41 | 42 | ==== Examples 43 | 44 | The following is a template that can be used when backing up a server containing a database. In this case, the include/exclude list initially includes files to back up the entire server. So this script does a hot backup of the database first, then adds to the exclude list the dbf files that were backed up initially, and then backs up the rest of the system. 45 | 46 | The Since these functions get called at various times from the snebu-client script, the order of the various code fragments can become a bit confusing. Pay attention to the "(Step x)" labels for the actual execution order in each fragment. 47 | 48 | .... 49 | ### Snebu backup plugin template for databases 50 | [ -z "${verbose}" ] && verbose=0 51 | [ "${verbose}" -gt 0 ] && echo "Executing client plugin template" >&2 52 | 53 | pluginpre=pluginpref 54 | pluginpost=pluginpostf 55 | # Initialize an internal housekeeping variable 56 | # (Step 0) 57 | dbstage=0 58 | 59 | # Define the pre-backup script 60 | pluginpref() { 61 | [ "${verbose}" -gt 0 ] && 62 | echo "Executing client plugin pre script" >&2 63 | # Stage 0 => haven't backed up the DB yet 64 | if [ "${dbstage}" = 0 ] 65 | then 66 | # (Step 1) 67 | # Save the current include/exclude list 68 | OLD_INCLUDE=( "${INCLUDE[@]}" ) 69 | OLD_EXCLUDE=( "${EXCLUDE[@]}" ) 70 | OLD_EXCLUDEMATCH=( "${EXCLUDEMATCH[@]}" ) 71 | 72 | # Zero out exclude list 73 | EXCLUDE=( ) 74 | EXCLUDEMATCH=( ) 75 | 76 | # Set the include list to include database files 77 | DBF_FILES=( "$( 78 | # Function to list database filenames to standard output 79 | print_dbf_filenames 80 | )" ) 81 | INCLUDE=( "${DBF_FILES[@]}" ) 82 | 83 | # Place DB in hot backup mode 84 | begin_db_backup 85 | 86 | # After this, snebu-client-backup takes over and backs up 87 | # the above set include list. Then control jumps to 88 | # pluginpost() with dbstage still set to 0 89 | elif [ "${dbstage}" = 1 ] 90 | then 91 | # (Step 3) 92 | DBF_LOG_FILES=( "$( 93 | # Function to list archived transaction logs 94 | print_dbf_log_filenames 95 | )" ) 96 | INCLUDE=( "${DBF_LOG_FILES[@]}" ) 97 | 98 | # Back to the backup with the new include list, then 99 | # off to pluginpost again with dbstage set to 1 100 | fi 101 | } 102 | 103 | pluginpostf() { 104 | [ "${verbose}" -gt 0 ] && echo "client plugin post" >&2 105 | if [ "${dbstage}" = 0 ] 106 | then 107 | # (Step 2) 108 | # Take DB out of hot backup mode 109 | end_db_backup 110 | 111 | # Define the next stage, and repeat the backup 112 | dbstage=1 113 | bkrepeat=1 114 | 115 | # Now control jumps back to pluginpre() with dbstage=1 116 | elif [ "${dbstage}" = 1 ] 117 | then 118 | # (Step 4) 119 | # Restore the original include/exclude list, with the 120 | # database files added to the exclude list. 121 | INCLUDE=( "${OLD_INCLUDE[@]}" ) 122 | EXCLUDE=( "${OLD_EXCLUDE[@]}" "${DBF_FILES[@]}" \ 123 | "${DBF_LOG_FILES[@]}" ) 124 | EXCLUDEMATCH=( "${OLD_EXCLUDEMATCH[@]}" ) 125 | 126 | # Define the next stage, and repeat the backup 127 | dbstage=2 128 | bkrepeat=1 129 | 130 | # Control jumps back to pluginpre(), however no more pre- 131 | # processing is needed for stage 2, so the backup begins 132 | # again with the original client include/exclude (plus the 133 | # above database files added to the exclude). 134 | elif [ "${dbstage}" = 2 ] 135 | then 136 | # (Step 5) 137 | # Break the cycle, backup is completed for this host. 138 | bkrepeat=0 139 | fi 140 | } 141 | 142 | # Also, don't forget to fill in the functions referenced above: 143 | 144 | begin_db_backup() { 145 | [ "${verbose}" -gt 0 ] && echo "Begin DB backup" >&2 146 | ### Steps to place DB in hot backup mode 147 | ### Make sure to execute these on the target host being backed 148 | ### up if running from the backup server (in pull mode) 149 | } 150 | 151 | end_db_backup() { 152 | [ "${verbose}" -gt 0 ] && echo "End DB backup" >&2 153 | ### Steps to DB out of hot backup mode 154 | ### Make sure to execute these on the target host being backed 155 | ### up if running from the backup server (in pull mode) 156 | } 157 | 158 | print_dbf_filenames() { 159 | [ "${verbose}" -gt 0 ] && echo "Generating DBF filenames" >&2 160 | ### Output list of dbf file names 161 | ### Make sure to execute these on the target host being backed 162 | ### up if running from the backup server (in pull mode) 163 | } 164 | 165 | print_dbf_log_filenames() { 166 | [ "${verbose}" -gt 0 ] && echo "Generating DBF log filenames" >&2 167 | ### Output list of archived transaction log file names 168 | ### Make sure to execute these on the target host being backed 169 | ### up if running from the backup server (in pull mode) 170 | } 171 | .... 172 | -------------------------------------------------------------------------------- /docs/snebu-client-restore.1: -------------------------------------------------------------------------------- 1 | .TH SNEBU-CLIENT-RESTORE "1" "December 2020" "snebu-client-restore" "User Commands" 2 | .na 3 | .SH NAME 4 | snebu-client restore \- Restores a backup 5 | .SH SYNOPSIS 6 | .B snebu-client 7 | \fBrestore\fR 8 | [ \fB-n\fR \fIbackupname\fR ] 9 | [ \fB-d\fR \fIdatestamp\fR ] 10 | [ \fIfile-list\fR ] 11 | .SH DESCRIPTION 12 | Restores a given backup session identified by "\-n" and "\-d" 13 | parameters. Use the "listbackups" subcommand to get a list of 14 | available backup sessions. 15 | .SH OPTIONS 16 | .TP 17 | \fB\-c\fR, \fB\-\-config\fR \fIconfig_file\fR 18 | Name of the configuration file. Default is 19 | \fI/etc/snebu\-client.conf\/\fP. 20 | .TP 21 | \fB\-n\fR, \fB\-\-name\fR \fIbackupname\fR 22 | Name of the backup. Usually set to the server 23 | name that you are backing up. 24 | .TP 25 | \fB\-d\fR, \fB\-\-date\fR \fIdatestamp\fR 26 | Date stamp for this backup set. The format is in 27 | time_t format, sames as the output of the "date 28 | +%s" command. 29 | .TP 30 | \fB\-\-decrypt\fR 31 | Turns on decryption. Requires "tarcrypt" to be 32 | on the client. Password(s) will be prompted for 33 | during restore. 34 | .IP 35 | By default, tarcrypt will be called if available 36 | which acts in pass through mode when processing 37 | unencrypted data. 38 | .TP 39 | \fB\-\-nodecrypt\fR 40 | Turns off decryption. Will cause unexpected 41 | results if backup contains any encrypted files. 42 | .TP 43 | \fB\-C\fR, \fB\-\-changedir\fR \fIpath\fR 44 | Changes to the given directory path before restoring. 45 | .TP 46 | \fB\-\-graft\fR \fI/path/name/\fR\fB=\fR\fI/new/name/\fR 47 | Re\-write path names beginning with "\fI/path/name/\fR" 48 | to "\fI/new/name/\fR" 49 | .TP 50 | \fB\-\-remote\-client\fR \fIhostname\fR 51 | Host name / IP address of remote host. Used to 52 | backup a remote host to local backup server. 53 | .TP 54 | \fB\-\-remote\-user\fR \fIuserid\fR 55 | User ID for remote remote\-client. 56 | Defaults to root. 57 | .TP 58 | \fB\-\-sudo\fR \fIuserid\fR 59 | Initial login User ID for remote remote\-client. 60 | This ID uses sudo to switch to remote\-user once 61 | logged in. 62 | .TP 63 | \fB\-\-backup\-server\fR \fIhostname\fR 64 | Host name / IP address of backup server. Used to 65 | backup to a remote server. 66 | .TP 67 | \fB\-\-backup\-user\fR \fIuserid\fR 68 | User ID for remote backup\-server. 69 | .TP 70 | [ \fIfile\-list\fR ] 71 | List of files to restore. Defaults to all. 72 | .SH "SEE ALSO" 73 | \fBtarcrypt\fR(1) 74 | .PP 75 | -------------------------------------------------------------------------------- /docs/snebu-client-restore_1.adoc: -------------------------------------------------------------------------------- 1 | === snebu-client-restore(1) - Restores a backup 2 | 3 | 4 | ---- 5 | snebu-client restore [ -n backupname ] [ -d datestamp ] [ file-list ] 6 | ---- 7 | 8 | ==== Description 9 | 10 | Restores a given backup session identified by "-n" and "-d" 11 | parameters. Use the "listbackups" subcommand to get a list of 12 | available backup sessions. 13 | 14 | ==== Options 15 | 16 | 17 | *-c*, *--config* _config_file_:: 18 | Name of the configuration file. Default is 19 | _/etc/snebu-client.conf_. 20 | 21 | *-n*, *--name* _backupname_:: 22 | Name of the backup. Usually set to the server 23 | name that you are backing up. 24 | 25 | *-d*, *--date* _datestamp_:: 26 | Date stamp for this backup set. The format is in 27 | time_t format, sames as the output of the "date 28 | +%s" command. 29 | 30 | *--decrypt*:: 31 | Turns on decryption. Requires "tarcrypt" to be 32 | on the client. Password(s) will be prompted for 33 | during restore. 34 | * By default, tarcrypt will be called if available 35 | which acts in pass through mode when processing 36 | unencrypted data. 37 | 38 | *--nodecrypt*:: 39 | Turns off decryption. Will cause unexpected 40 | results if backup contains any encrypted files. 41 | 42 | *-C*, *--changedir* _path_:: 43 | Changes to the given directory path before restoring. 44 | 45 | *--graft* _/path/name/_*=*_/new/name/_:: 46 | Re-write path names beginning with "_/path/name/_" 47 | to "_/new/name/_" 48 | 49 | *--remote-client* _hostname_:: 50 | Host name / IP address of remote host. Used to 51 | backup a remote host to local backup server. 52 | 53 | *--remote-user* _userid_:: 54 | User ID for remote remote-client. 55 | Defaults to root. 56 | 57 | *--sudo* _userid_:: 58 | Initial login User ID for remote remote-client. 59 | This ID uses sudo to switch to remote-user once 60 | logged in. 61 | 62 | *--backup-server* _hostname_:: 63 | Host name / IP address of backup server. Used to 64 | backup to a remote server. 65 | 66 | *--backup-user* _userid_:: 67 | User ID for remote backup-server. 68 | 69 | [ _file-list_ ]:: 70 | List of files to restore. Defaults to all. 71 | 72 | ==== See Also 73 | 74 | *tarcrypt*(1) 75 | -------------------------------------------------------------------------------- /docs/snebu-client-validate.1: -------------------------------------------------------------------------------- 1 | .TH SNEBU-CLIENT-VALIDATE "1" "December 2020" "snebu-client-validate" "User Commands" 2 | .na 3 | .SH NAME 4 | snebu-client validate \- Compares a backup to file system contents 5 | .SH SYNOPSIS 6 | .B snebu-client 7 | \fBvalidate\fR 8 | \fB-n\fR \fIbackupname\fR 9 | \fB-d\fR \fIdatestamp\fR 10 | [ \fIfile-list\fR ] 11 | .SH DESCRIPTION 12 | Compares the contents a given backup session identified by "\-n" and "\-d" 13 | parameters, to what is on the client. Use the "listbackups" subcommand to 14 | get a list of available 15 | backup sessions. 16 | .SH OPTIONS 17 | .TP 18 | \fB\-c\fR, \fB\-\-config\fR \fIconfig_file\fR 19 | Name of the configuration file. Default is 20 | \fI/etc/snebu\-client.conf\/\fP. 21 | .TP 22 | \fB\-n\fR, \fB\-\-name\fR \fIbackupname\fR 23 | Name of the backup. Usually set to the server 24 | name that you are backing up. 25 | .TP 26 | \fB\-d\fR, \fB\-\-date\fR \fIdatestamp\fR 27 | Date stamp for this backup set. The format is in 28 | time_t format, sames as the output of the "date 29 | +%s" command. 30 | .TP 31 | \fB\-\-decrypt\fR 32 | Turns on decryption. Requires "tarcrypt" to be 33 | on the client. Password(s) will be prompted for 34 | during restore. 35 | .TP 36 | \fB\-C\fR, \fB\-\-changedir\fR \fIpath\fR 37 | Changes to the given directory path before validating 38 | .TP 39 | \fB\-\-remote\-client\fR \fIhostname\fR 40 | Host name / IP address of remote host. Used to 41 | backup a remote host to local backup server. 42 | .TP 43 | \fB\-\-remote\-user\fR \fIuserid\fR 44 | User ID for remote remote\-client. Defaults to 45 | root. 46 | .TP 47 | \fB\-\-sudo\fR \fIuserid\fR 48 | Initial login User ID for remote remote\-client. 49 | This ID uses sudo to switch to remote\-user once 50 | logged in. 51 | .TP 52 | \fB\-\-backup\-server\fR \fIhostname\fR 53 | Host name / IP address of backup server. Used to 54 | backup to a remote server. 55 | .TP 56 | \fB\-\-backup\-user\fR \fIuserid\fR 57 | User ID for remote backup\-server. 58 | .TP 59 | [ \fIfile\-list\fR ] 60 | List of files to validate. Defaults to all. 61 | .SH "SEE ALSO" 62 | \fBtarcrypt\fR(1) 63 | .PP 64 | -------------------------------------------------------------------------------- /docs/snebu-client-validate_1.adoc: -------------------------------------------------------------------------------- 1 | === snebu-client-validate(1) - Compares a backup to file system contents 2 | 3 | 4 | ---- 5 | snebu-client validate -n backupname -d datestamp [ file-list ] 6 | ---- 7 | 8 | ==== Description 9 | 10 | Compares the contents a given backup session identified by "-n" and "-d" 11 | parameters, to what is on the client. Use the "listbackups" subcommand to 12 | get a list of available 13 | backup sessions. 14 | 15 | ==== Options 16 | 17 | 18 | *-c*, *--config* _config_file_:: 19 | Name of the configuration file. Default is 20 | _/etc/snebu-client.conf_. 21 | 22 | *-n*, *--name* _backupname_:: 23 | Name of the backup. Usually set to the server 24 | name that you are backing up. 25 | 26 | *-d*, *--date* _datestamp_:: 27 | Date stamp for this backup set. The format is in 28 | time_t format, sames as the output of the "date 29 | +%s" command. 30 | 31 | *--decrypt*:: 32 | Turns on decryption. Requires "tarcrypt" to be 33 | on the client. Password(s) will be prompted for 34 | during restore. 35 | 36 | *-C*, *--changedir* _path_:: 37 | Changes to the given directory path before validating 38 | 39 | *--remote-client* _hostname_:: 40 | Host name / IP address of remote host. Used to 41 | backup a remote host to local backup server. 42 | 43 | *--remote-user* _userid_:: 44 | User ID for remote remote-client. Defaults to 45 | root. 46 | 47 | *--sudo* _userid_:: 48 | Initial login User ID for remote remote-client. 49 | This ID uses sudo to switch to remote-user once 50 | logged in. 51 | 52 | *--backup-server* _hostname_:: 53 | Host name / IP address of backup server. Used to 54 | backup to a remote server. 55 | 56 | *--backup-user* _userid_:: 57 | User ID for remote backup-server. 58 | 59 | [ _file-list_ ]:: 60 | List of files to validate. Defaults to all. 61 | 62 | ==== See Also 63 | 64 | *tarcrypt*(1) 65 | -------------------------------------------------------------------------------- /docs/snebu-client.1: -------------------------------------------------------------------------------- 1 | .TH SNEBU-CLIENT "1" "December 2020" "snebu-client" "User Commands" 2 | .na 3 | .SH NAME 4 | snebu-client \- Front-end client for the snebu backup system 5 | .SH SYNOPSIS 6 | .B snebu-client 7 | [ \fIsubcommand \/\fR] [ \fIoptions \/\fR] 8 | .SH DESCRIPTION 9 | snebu\-client is the client front end for snebu. 10 | Use it to easily 11 | back up a local or remote host, to either local a local storage 12 | device, or to a remote backup server. Use it with one of the 13 | following subcommands. 14 | .SS "Sub commands are as follows:" 15 | .TP 16 | \fBbackup\fR [ \fB\-n\fR \fIbackupname\fR ] [ \fB\-d\fR \fIdatestamp\fR ] [ \fB\-r\fR \fIschedule\fR ] 17 | Initiates a backup. 18 | .TP 19 | \fBrestore\fR [ \fB\-n\fR \fIbackupname\fR ] [ \fB\-d\fR \fIdatestamp\fR ] 20 | Initiates a restore. 21 | .TP 22 | \fBlistbackups\fR [ \fB\-n\fR \fIbackupname\fR [ \fB\-d\fR \fIdatestamp\fR ]] [ \fIfile_list\fR... ] 23 | List backed up hosts, backup sets within a host, or files within a backup set. 24 | .TP 25 | \fBvalidate\fR \fB\-n\fR \fIbackupname\fR \fB\-d\fR \fIdatestamp\fR 26 | Validates a given backup. 27 | .TP 28 | \fBhelp\fR [ \fIsubcommand\fR ] 29 | Displays help page of subcommand 30 | .RE 31 | .SH "SEE ALSO" 32 | .hy 0 33 | \fBsnebu\-client\-backup\fR(1), 34 | \fBsnebu\-client\-restore\fR(1), 35 | \fBsnebu\-client\-listbackups\fR(1), 36 | \fBsnebu\-client\-validate\fR(1), 37 | .PP 38 | .RE 39 | -------------------------------------------------------------------------------- /docs/snebu-client.conf.5: -------------------------------------------------------------------------------- 1 | .TH SNEBU-CLIENT.CONF "5" "December 2020" "snebu-client.conf" "File Formats" 2 | .na 3 | .SH NAME 4 | snebu-client.conf - Configuration file for snebu-client front end 5 | .SH DESCRIPTION 6 | The sneub-client.conf is used to specify a number of default parameters for snebu-client, such as default include / exclude specifications. The contents are read in and executed as shell script commands by snebu-client, so in addition to specifying parameters it is possible to include standard shell scripting logic. This also means that parameters are specified without a space between the name and value. 7 | 8 | .SS Parameters 9 | .TP 10 | \fBINCLUDE\fR=( \fIpath\fR ... ) 11 | Specifies the directories to include in the backup. By default, all mounted storage-based file systems are included -- that is, file systems that are of type "NODEV" (which includes virtual file systems such as /proc, /sys, anything mounted as "tmpdir") are not included. 12 | 13 | Also note that file system boundaries are not crossed automatically. For example, if "/home" is a separate mount point from "/" then you will need to specify both "/" and "/home". Mount points are specified explicitly to prevent virtual file systems (i.e., "/proc") from being inadvertently included. 14 | 15 | .TP 16 | \fBEXCLUDE\fR=( \fIpath\fR ...) 17 | Excludes directories that would normally be included with the above INCLUDE parameter. 18 | .PP 19 | .TP 20 | \fBEXCLUDEMATCH\fR=( \fIfilespec\fR... ) 21 | Similar to EXCLUDE, however works with files matching a given pattern (processing shell wildcard expansion). Note that individual parameters need to be quoted to prevent wildcard expansion from matching only files in the current directory. 22 | .PP 23 | .TP 24 | \fBbackupname\fR=\fIname-of-backup\fR 25 | Give the backup the given name instead of defaulting to the hostname. 26 | .PP 27 | .SS Server-initiated backup notes 28 | If running backups from a backup server, the parameters will by default apply to all clients. To target parameters for specific clients, you can wrap them in a shell scripting conditional clause (if-then-else, or case statement). 29 | 30 | .SH EXAMPLES: 31 | To include specified directories: 32 | .RS 33 | .PP 34 | .nf 35 | INCLUDE=( / /var /var/log /home ) 36 | .fi 37 | .RE 38 | .PP 39 | To exclude /tmp and /var/tmp 40 | .RS 41 | .PP 42 | .nf 43 | EXCLUDE=( /tmp /var/tmp ) 44 | .fi 45 | .RE 46 | .PP 47 | To exclude all ".tmp" and ".dbf" files 48 | .RS 49 | .PP 50 | .nf 51 | EXCLUDEMATCH=( "*.tmp" "*.dbf" ) 52 | .fi 53 | .RE 54 | .PP 55 | On a server backing up multiple clients -- to exclude all database ".dbf" files only on the database server "erp-database", include the following: 56 | .RS 57 | .PP 58 | .nf 59 | if [ "${clientname}" = "erp-database" ] 60 | then 61 | EXCLUDEMATCH=( "*.dbf" ) 62 | fi 63 | .fi 64 | .RE 65 | .PP 66 | -------------------------------------------------------------------------------- /docs/snebu-client.conf_5.adoc: -------------------------------------------------------------------------------- 1 | === snebu-client.conf(5) - Configuration file for snebu-client front end 2 | 3 | 4 | ==== Description 5 | 6 | The sneub-client.conf is used to specify a number of default parameters for snebu-client, such as default include / exclude specifications. The contents are read in and executed as shell script commands by snebu-client, so in addition to specifying parameters it is possible to include standard shell scripting logic. This also means that parameters are specified without a space between the name and value. 7 | 8 | [discrete] 9 | ==== Parameters 10 | 11 | 12 | *INCLUDE*=( _path_ ... ):: 13 | Specifies the directories to include in the backup. By default, all mounted storage-based file systems are included -- that is, file systems that are of type "NODEV" (which includes virtual file systems such as /proc, /sys, anything mounted as "tmpdir") are not included. 14 | + 15 | Also note that file system boundaries are not crossed automatically. For example, if "/home" is a separate mount point from "/" then you will need to specify both "/" and "/home". Mount points are specified explicitly to prevent virtual file systems (i.e., "/proc") from being inadvertently included. 16 | 17 | 18 | *EXCLUDE*=( _path_ ...):: 19 | Excludes directories that would normally be included with the above INCLUDE parameter. 20 | 21 | *EXCLUDEMATCH*=( _filespec_... ):: 22 | Similar to EXCLUDE, however works with files matching a given pattern (processing shell wildcard expansion). Note that individual parameters need to be quoted to prevent wildcard expansion from matching only files in the current directory. 23 | 24 | *backupname*=_name-of-backup_:: 25 | Give the backup the given name instead of defaulting to the hostname. 26 | 27 | [discrete] 28 | ==== Server-initiated backup notes 29 | 30 | If running backups from a backup server, the parameters will by default apply to all clients. To target parameters for specific clients, you can wrap them in a shell scripting conditional clause (if-then-else, or case statement). 31 | 32 | ==== Examples: 33 | 34 | To include specified directories: 35 | 36 | INCLUDE=( / /var /var/log /home ) 37 | 38 | To exclude /tmp and /var/tmp 39 | 40 | EXCLUDE=( /tmp /var/tmp ) 41 | 42 | To exclude all ".tmp" and ".dbf" files 43 | 44 | EXCLUDEMATCH=( "*.tmp" "*.dbf" ) 45 | 46 | On a server backing up multiple clients -- to exclude all database ".dbf" files only on the database server "erp-database", include the following: 47 | 48 | if [ "${clientname}" = "erp-database" ] 49 | then 50 | EXCLUDEMATCH=( "*.dbf" ) 51 | fi 52 | -------------------------------------------------------------------------------- /docs/snebu-client_1.adoc: -------------------------------------------------------------------------------- 1 | === snebu-client(1) - Front-end client for the snebu backup system 2 | 3 | 4 | ---- 5 | snebu-client [ subcommand ] [ options ] 6 | ---- 7 | 8 | ==== Description 9 | 10 | snebu-client is the client front end for snebu. 11 | Use it to easily 12 | back up a local or remote host, to either local a local storage 13 | device, or to a remote backup server. Use it with one of the 14 | following subcommands. 15 | 16 | [discrete] 17 | ==== Sub commands are as follows: 18 | 19 | 20 | *backup* [ *-n* _backupname_ ] [ *-d* _datestamp_ ] [ *-r* _schedule_ ]:: 21 | Initiates a backup. 22 | 23 | *restore* [ *-n* _backupname_ ] [ *-d* _datestamp_ ]:: 24 | Initiates a restore. 25 | 26 | *listbackups* [ *-n* _backupname_ [ *-d* _datestamp_ ]] [ _file_list_... ]:: 27 | List backed up hosts, backup sets within a host, or files within a backup set. 28 | 29 | *validate* *-n* _backupname_ *-d* _datestamp_:: 30 | Validates a given backup. 31 | 32 | *help* [ _subcommand_ ]:: 33 | Displays help page of subcommand 34 | 35 | ==== See Also 36 | 37 | *snebu-client-backup*(1), 38 | *snebu-client-restore*(1), 39 | *snebu-client-listbackups*(1), 40 | *snebu-client-validate*(1), 41 | -------------------------------------------------------------------------------- /docs/snebu-concepts.adoc: -------------------------------------------------------------------------------- 1 | == General Concepts 2 | 3 | === Components 4 | 5 | The Snebu backup system consists of a backend process `snebu`, which maintains a backup catalog in an SQLite database `snebu-catalog.db` in the directory specified in the `/etc/snebu.conf` file. This database has a number of tables, containing entries for each host that is backed up, along with the backup sets, all file metadata, and backup set details which relate the contents of a given backup set snapshot to to files in the file details table. Individual file contents are compressed and a file hash is computed. The files are stored in file names reflecting the file hash in the vault directory (again as specified in the config file). Storing files named by the hash of the file contents leads directly to file-level deduplication across directories and hosts. 6 | 7 | When initiating a backup, a file manifest of the system to be backed up is sent to `snebu` -- this manifest consists of a list of file names and all associated metadata (ownership, permissions, size, modification times, etc). This represents a complete snapshot of backed up file set. This manifest gets processed to determine which files are already on the backup server. The names of new and modified files (as determined by changes in _any_ of the metadata fields) are returned to the client, which is then passed to the `tar` command to process and create a backup. 8 | 9 | The output of `tar` is then ingested by the `snebu` backend process, which extracts the file names and meta data, then compresses the contents of each file to a temporary staging file in the `vault` location. After computing a sha1 hash of the file, the file is renamed to this hash and placed in the target location in the vault. 10 | 11 | The `snebu-client` program acts as a front end to `snebu`. Technically it isn't necessary, however you would need to generate the manifest manually (using `find` and a specific list of `-printf` specifiers -- consult the man page `snebu-newbackup(1)` for details), and send it into `snebu --newbackup`, capture the return manifest to use to generate a `tar` file, and finally sending that into `snebu --submitfiles`. 12 | 13 | Note, that some subcommands share the same name between `snebu` and `snebu-client`. In some cases, such as `listbackups`, there is a bit more front-end processing provided by `snebu-client`. In other cases, such as `restore`, the actions are different. `snebu restore` synthesizes a `tar` file on standard output, whereas `snebu-client restore` executes `snebu restore` and calls the local `tar` command to extract the files. 14 | 15 | === Encryption 16 | 17 | Since `snebu` uses `tar` as a serialization format for the backup data, the `tarcrypt` command was created to act as a filter in a `tar` pipeline in order to add encryption capabilities. The key used by `tarcrypt` contains an RSA Public key which is used to encrypt a random session key for each file. It also contains a secret HMAC key used to "sign" each file in the backup with a deterministic hash. The HMAC key is computed using a combination of the RSA Public key and the passphrase used to protect the RSA Private key. That way it can not only be reliably regenerated during a restore operation (since the user needs to input the same passphrase to decrypt the backup), but it is also directly tied to the combination of the RSA keys and passphrase. Since the HMAC key is considered sensitive, the `.key` file should be stored with appropriate restricted ownership and permissions to prevent an attacker from forging backup file contents (although a compromised HMAC key still won't permit an attacker from decrypting a backup). 18 | 19 | Since the backup server can't know the hash of the raw file, and since a random session key is used when encrypting, that means that the has of the received file can't be utilized for deduplication purposes. However since the HMAC signature is deterministic, this signature is utilized for deduplication purposes which works to deduplicate across any hosts that share the same key file(s). (When multiple keys are used during encryption, a hash of all the HMAC keys is used to name the file). 20 | 21 | If a new key is generated, then subsequent backups will consist of files encrypted with the old key and the new one (since backups are snapshot based, only new/modified files get sent to the backup server and encrypted with the new key). The `tarcrypt` command handles this gracefully -- the global header contains all the encrypted keys used that are related to the files in the restore set, so the operator will be prompted for the passphrase for each key. As an ease-of-use operation, if the same passphrase is used on more than one key, it only has to be entered once -- it will automatically be tested against all keys. 22 | 23 | You also have the option to force a full backup, which will re-send all files on the client to the backup server, if you don't want to deal with multiple keys, by specifying the `--force-full` parameter (`snebu-client backup --force-full ...`). 24 | 25 | === Other security features 26 | 27 | If the `snebu` binary is installed with the suid bit set, then the user that owns it (the `snebu` user in the default case) will own the backup catalog database and the data vault. Other users on the system can be given access to specific features, restricted to the specified hosts by using the `snebu permissions` subcommand. For example you can give a user access to back up their host, but not restore. Or you can restrict their ability to expire backups -- either give permission for a host to only expire their own backups, or restrict expire option to a separate locked down account. This can be valuable to prevent an attacker from deleting all the backups if a host is compromised. 28 | -------------------------------------------------------------------------------- /docs/snebu-expire.1: -------------------------------------------------------------------------------- 1 | .TH SNEBU-EXPIRE "1" "December 2020" "snebu-expire" "User Commands" 2 | .na 3 | .SH NAME 4 | snebu expire \- Expire a given backup set or range of backups 5 | .SH SYNOPSIS 6 | .B snebu 7 | \fBexpire\fR [ \fB-n\fR \fIhostname\fR 8 | \fB-d\fR \fIdatestamp\fR ] or 9 | [ \fB-a\fR \fIdays\fR 10 | \fB-r\fR \fIschedule\fR 11 | [ \fB\-n\fR \fIhostname\fR ]] 12 | .SH DESCRIPTION 13 | Removes backup sessions from the snebu backup catalog database. 14 | A specific backup session can be purged by providing the \fB\-n\fR and \fB\-d\fR 15 | options, or all backups that are part of a given retention schedule 16 | (specified with \fB\-r\fR, and optionally from a given host, with the \fB\-n\fR 17 | option) that are older than a given number of days (\fB\-a\fR) are removed. 18 | .SH OPTIONS 19 | .TP 20 | \fB\-n\fR, \fB\-\-name\fR \fIbackupname\fR 21 | Name of the backup. Usually set to the server 22 | name that you are backing up. 23 | .TP 24 | \fB\-d\fR, \fB\-\-date\fR \fIdatestamp\fR 25 | Date stamp for this backup set. The format is in 26 | time_t format, sames as the output of the "date 27 | +%s" command. 28 | .TP 29 | \fB\-r\fR, \fB\-\-retention\fR \fIschedule\fR 30 | Retention schedule for this backup set. Typical 31 | values are "daily", "weekly", "monthly", "yearly". 32 | .TP 33 | \fB\-a\fR, \fB\-\-age\fR \fI#days\fR 34 | Expire backups older than #days. 35 | .TP 36 | \fB\-m\fR, \fB\-\-min\-keep\fR \fI#backups\fR 37 | When expiring with the \fB\-a\fR flag, keep at least 38 | this many of the most recent backups for a given 39 | hostname/retention schedule. 40 | Defaults to 3 days. 41 | .SH "SEE ALSO" 42 | .hy 0 43 | \fBsnebu\fR(1), 44 | \fBsnebu\-newbackup\fR(1), 45 | \fBsnebu\-submitfiles\fR(1), 46 | \fBsnebu\-restore\fR(1), 47 | \fBsnebu\-listbackups\fR(1), 48 | \fBsnebu\-purge\fR(1), 49 | \fBsnebu\-permissions\fR(1), 50 | \fBsnebu\-client\fR(1) 51 | .PP 52 | -------------------------------------------------------------------------------- /docs/snebu-expire_1.adoc: -------------------------------------------------------------------------------- 1 | === snebu-expire(1) - Expire a given backup set or range of backups 2 | 3 | 4 | ---- 5 | snebu expire [ -n hostname -d datestamp ] or [ -a days -r schedule [ -n hostname ]] 6 | ---- 7 | 8 | ==== Description 9 | 10 | Removes backup sessions from the snebu backup catalog database. 11 | A specific backup session can be purged by providing the *-n* and *-d* 12 | options, or all backups that are part of a given retention schedule 13 | (specified with *-r*, and optionally from a given host, with the *-n* 14 | option) that are older than a given number of days (*-a*) are removed. 15 | 16 | ==== Options 17 | 18 | 19 | *-n*, *--name* _backupname_:: 20 | Name of the backup. Usually set to the server 21 | name that you are backing up. 22 | 23 | *-d*, *--date* _datestamp_:: 24 | Date stamp for this backup set. The format is in 25 | time_t format, sames as the output of the "date 26 | +%s" command. 27 | 28 | *-r*, *--retention* _schedule_:: 29 | Retention schedule for this backup set. Typical 30 | values are "daily", "weekly", "monthly", "yearly". 31 | 32 | *-a*, *--age* _#days_:: 33 | Expire backups older than #days. 34 | 35 | *-m*, *--min-keep* _#backups_:: 36 | When expiring with the *-a* flag, keep at least 37 | this many of the most recent backups for a given 38 | hostname/retention schedule. 39 | Defaults to 3 days. 40 | 41 | ==== See Also 42 | 43 | *snebu*(1), 44 | *snebu-newbackup*(1), 45 | *snebu-submitfiles*(1), 46 | *snebu-restore*(1), 47 | *snebu-listbackups*(1), 48 | *snebu-purge*(1), 49 | *snebu-permissions*(1), 50 | *snebu-client*(1) 51 | -------------------------------------------------------------------------------- /docs/snebu-intro.adoc: -------------------------------------------------------------------------------- 1 | == Introduction 2 | 3 | Snebu is a high-performance snapshot-style backup system for Linux supporting compression, deduplication and optional public key encryption. It can operate in single-host mode, push mode (client pushes data to server), or pull mode (server pulls data from client) via SSH. In pull mode, no agent is required on the client (the program _tarcrypt_ will need to be on clients when encryption is used). 4 | 5 | The backups are snapshot style, so only the minimum necessary files are transferred to the backup server to complete a backup set. This keeps storage and bandwidth utilization to a minimum. 6 | 7 | Server side is accessed via SSH, supports multiple simultaneous clients, and deduplicates backup files across file systems, clients and backup sets. Server access supports multi-user granular permissions per account (i.e., an account can be granted backup access, but forbidden delete access -- useful for protection against malware attacks). 8 | 9 | 10 | [discrete] 11 | === Primary Features 12 | * Centrally managed 13 | * Snapshot backups 14 | * Database-backed metadata catalog 15 | * File-level deduplication 16 | ** Across backup sets and clients 17 | * Compression 18 | * RSA Public Key encryption 19 | * Single-host, Client-push, or Server-pull backups 20 | * Multiple user granular access 21 | * Agentless 22 | ** Client-side uses standard Unix/Linux commands -- _find_, _tar_, _ssh_, _bash_ 23 | * High efficiency C code 24 | ** Minimal library runtime dependencies -- _SQLite_, _OpenSSL_, _LZOP_ 25 | 26 | _SNEBU -- Sleep Nominally, Everything's Backed Up._ 27 | -------------------------------------------------------------------------------- /docs/snebu-listbackups.1: -------------------------------------------------------------------------------- 1 | .TH SNEBU-LISTBACKUPS "1" "December 2020" "snebu-listbackups" "User Commands" 2 | .na 3 | .SH NAME 4 | snebu listbackups \- Lists backed up systems, backup sets, and file names 5 | .SH SYNOPSIS 6 | .B snebu 7 | \fBlistbackups\fR 8 | [ \fB-n\fR \fIhostname\fR ] [ \fB-d\fR \fIdatestamp\fR ]] 9 | [ \fIfile_list\fR... ] 10 | .SH DESCRIPTION 11 | With no arguments specified, \fIlistbackups\fR will return a list of all 12 | systems that are contained in the backup catalog. Otherwise, when 13 | specifying the \fB\-n\fR parameter, a list of backup sets for that host is 14 | returned. 15 | .SH OPTIONS 16 | .TP 17 | \fB\-n\fR, \fB\-\-name\fR \fIbackupname\fR 18 | Name of the backup. Usually set to the server 19 | name that you are backing up. 20 | .TP 21 | \fB\-d\fR, \fB\-\-date\fR \fIdatestamp\fR 22 | Date stamp for this backup set. The format is in 23 | time_t format, sames as the output of the "date 24 | +%s" command. 25 | .TP 26 | [ \fIfile\-list\fR ] 27 | List of files or file pattern(s) 28 | .SH "SEE ALSO" 29 | .hy 0 30 | \fBsnebu\fR(1), 31 | \fBsnebu\-newbackup\fR(1), 32 | \fBsnebu\-submitfiles\fR(1), 33 | \fBsnebu\-restore\fR(1), 34 | \fBsnebu\-expire\fR(1), 35 | \fBsnebu\-purge\fR(1), 36 | \fBsnebu\-permissions\fR(1), 37 | \fBsnebu\-client\fR(1) 38 | .PP 39 | -------------------------------------------------------------------------------- /docs/snebu-listbackups_1.adoc: -------------------------------------------------------------------------------- 1 | === snebu-listbackups(1) - Lists backed up systems, backup sets, and file names 2 | 3 | 4 | ---- 5 | snebu listbackups [ -n hostname ] [ -d datestamp ]] [ file_list... ] 6 | ---- 7 | 8 | ==== Description 9 | 10 | With no arguments specified, _listbackups_ will return a list of all 11 | systems that are contained in the backup catalog. Otherwise, when 12 | specifying the *-n* parameter, a list of backup sets for that host is 13 | returned. 14 | 15 | ==== Options 16 | 17 | 18 | *-n*, *--name* _backupname_:: 19 | Name of the backup. Usually set to the server 20 | name that you are backing up. 21 | 22 | *-d*, *--date* _datestamp_:: 23 | Date stamp for this backup set. The format is in 24 | time_t format, sames as the output of the "date 25 | +%s" command. 26 | 27 | [ _file-list_ ]:: 28 | List of files or file pattern(s) 29 | 30 | ==== See Also 31 | 32 | *snebu*(1), 33 | *snebu-newbackup*(1), 34 | *snebu-submitfiles*(1), 35 | *snebu-restore*(1), 36 | *snebu-expire*(1), 37 | *snebu-purge*(1), 38 | *snebu-permissions*(1), 39 | *snebu-client*(1) 40 | -------------------------------------------------------------------------------- /docs/snebu-newbackup.1: -------------------------------------------------------------------------------- 1 | .TH SNEBU-NEWBACKUP "1" "December 2020" "snebu-newbackup" "User Commands" 2 | .na 3 | .SH NAME 4 | snebu newbackup \- Submits manifest for a new backup 5 | .SH SYNOPSIS 6 | .B snebu 7 | \fBnewbackup\fR 8 | \fB-n\fR \fIbackupname\fR 9 | \fB-d\fR \fIdatestamp\fR 10 | \fB-r\fR \fIschedule\fR 11 | .SH DESCRIPTION 12 | The "newbackup" command creates a new backup set, by consuming a 13 | tab\-delimited list of file names (along with associated meta data) to 14 | include in the backup. It then compares this list to the backup 15 | catalog database to determine which files are new, and which ones are 16 | already contained on the backup media. A list of new / changed files 17 | is returned (the snapshot manifest), which can then be passed along to 18 | "tar" to generate the input for the "submitfiles" subcommand. 19 | .SH OPTIONS 20 | .TP 21 | \fB\-n\fR, \fB\-\-name\fR \fIbackupname\fR 22 | Name of the backup. Usually set to the server 23 | name that you are backing up. 24 | .TP 25 | \fB\-d\fR, \fB\-\-date\fR \fIdatestamp\fR 26 | Date stamp for this backup set. The format is in 27 | time_t format, sames as the output of the "date 28 | +%s" command. 29 | .TP 30 | \fB\-r\fR, \fB\-\-retention\fR \fIschedule\fR 31 | Retention schedule for this backup set. Typical 32 | values are "daily", "weekly", "monthly", "yearly". 33 | .TP 34 | \fB\-T\fR, \fB\-\-files\-from\fR \fIFILE\fR 35 | Read list of filenames (with meta data) to backup 36 | from the named file, instead of standard input. 37 | .TP 38 | \fB\-\-null\fR 39 | Inbound backup manifest (\fB\-T\fR, or standard input) 40 | is null terminated 41 | .TP 42 | \fB\-\-not\-null\fR 43 | Inbound backup manifest (\fB\-T\fR, or standard input) 44 | is newline terminated 45 | .TP 46 | \fB\-\-null\-output\fR 47 | Generate snapshot manifest with null-terminated lines. 48 | .TP 49 | \fB\-\-not\-null\-output\fR 50 | Generate snapshot with newline-terminated lines. 51 | .TP 52 | \fB\-f\fR, \fB\-\-force\-full\fR 53 | Force a full backup 54 | .TP 55 | \fB\-\-graft\fR \fI/path/name/\fR\fB=\fR\fI/new/name/\fR 56 | Re\-write path names beginning with "\fI/path/name/\fR" 57 | to "\fI/new/name/\fR" 58 | .TP 59 | \fB\-v\fR 60 | Turn on verbose output. 61 | .SS Input Manifest format 62 | The input manifest contains a list of files to include in this backup set. 63 | The format is a delimited list of file names and file metadata, with the following fields: 64 | .BP 65 | .PP 66 | .TP 67 | .B 1 - FType 68 | Values are one of "f", "d", "l", "c", "b" 69 | .TP 70 | .B 2 - Mode 71 | File mode in octal 72 | .TP 73 | .B 3 - Device 74 | Device number of file system 75 | .TP 76 | .B 4 - Inode 77 | Inode number of file 78 | .TP 79 | .B 5 - UName 80 | User name 81 | .TP 82 | .B 6 - UID 83 | User ID number 84 | .TP 85 | .B 7 - GName 86 | User's Group Name 87 | .TP 88 | .B 8 - GID 89 | User's Group Number 90 | .TP 91 | .B 9 - Size 92 | File size in bytes 93 | .TP 94 | .B 10 - Hash 95 | File Hash (future use, set to "0") 96 | .TP 97 | .B 11 - CTime 98 | File Inode's last change time 99 | .TP 100 | .B 12 - MTime 101 | File Content's last modififed time 102 | .TP 103 | .B 13 - Path 104 | Full file path 105 | .TP 106 | .B 14 - LTarget 107 | Link target 108 | .PP 109 | Field 14 (Link Target) is only present if the file type is "l" (symbolic link). 110 | .PP 111 | The fields are tab-delimited. If the "--null" option is specified, then each line is null terminated, with an additional null character delimiting fields 13 and 14. Otherwise if "--not-null" is specified, fields 13 and 14 are tab delimited, and the path names must have special characters escaped. 112 | .PP 113 | The input manifest can be created with the GNU \fIfind\fR command, with the following print formatting specification (suitable for the "--null" flag): 114 | .RS 115 | .PP 116 | .EX 117 | find [ parameters ] \\( -type f -o -type d \\) \\ 118 | .br 119 | -printf "%y\t%#m\t%D\t%i\t%u\t%U\t%g\t%G\t%s\t0\t%C@\t%T@\t%p\\0" \\ 120 | .br 121 | -o -type l -printf "%y\t%#m\t%D\t%i\t%u\t%U\t%g\t%G\t%s\t0\t%C@\t%T@\t%p\\0%l\\0" 122 | .EE 123 | .RE 124 | .SS Returned Snapshot manifest output 125 | .PP 126 | The manifest returned is either a null-delimited list of files (if "--null-output" is specified), 127 | or a newline-delimited list of files with special characters escaped (if "--not-null-output is specified). 128 | This is the list of files that are required to complete the snapshot (any file that hasn't changed from previous backups will be referenced from the backup server). This list is suitable for passing into the \fItar\fR command. 129 | .SH "SEE ALSO" 130 | .hy 0 131 | \fBsnebu\fR(1), 132 | \fBsnebu\-submitfiles\fR(1), 133 | \fBsnebu\-restore\fR(1), 134 | \fBsnebu\-listbackups\fR(1), 135 | \fBsnebu\-expire\fR(1), 136 | \fBsnebu\-purge\fR(1), 137 | \fBsnebu\-permissions\fR(1), 138 | \fBsnebu\-client\fR(1) 139 | .PP 140 | -------------------------------------------------------------------------------- /docs/snebu-newbackup_1.adoc: -------------------------------------------------------------------------------- 1 | === snebu-newbackup(1) - Submits manifest for a new backup 2 | 3 | 4 | ---- 5 | snebu newbackup -n backupname -d datestamp -r schedule 6 | ---- 7 | 8 | ==== Description 9 | 10 | The "newbackup" command creates a new backup set, by consuming a 11 | tab-delimited list of file names (along with associated meta data) to 12 | include in the backup. It then compares this list to the backup 13 | catalog database to determine which files are new, and which ones are 14 | already contained on the backup media. A list of new / changed files 15 | is returned (the snapshot manifest), which can then be passed along to 16 | "tar" to generate the input for the "submitfiles" subcommand. 17 | 18 | ==== Options 19 | 20 | 21 | *-n*, *--name* _backupname_:: 22 | Name of the backup. Usually set to the server 23 | name that you are backing up. 24 | 25 | *-d*, *--date* _datestamp_:: 26 | Date stamp for this backup set. The format is in 27 | time_t format, sames as the output of the "date 28 | +%s" command. 29 | 30 | *-r*, *--retention* _schedule_:: 31 | Retention schedule for this backup set. Typical 32 | values are "daily", "weekly", "monthly", "yearly". 33 | 34 | *-T*, *--files-from* _FILE_:: 35 | Read list of filenames (with meta data) to backup 36 | from the named file, instead of standard input. 37 | 38 | *--null*:: 39 | Inbound backup manifest (*-T*, or standard input) 40 | is null terminated 41 | 42 | *--not-null*:: 43 | Inbound backup manifest (*-T*, or standard input) 44 | is newline terminated 45 | 46 | *--null-output*:: 47 | Generate snapshot manifest with null-terminated lines. 48 | 49 | *--not-null-output*:: 50 | Generate snapshot with newline-terminated lines. 51 | 52 | *-f*, *--force-full*:: 53 | Force a full backup 54 | 55 | *--graft* _/path/name/_*=*_/new/name/_:: 56 | Re-write path names beginning with "_/path/name/_" 57 | to "_/new/name/_" 58 | 59 | *-v*:: 60 | Turn on verbose output. 61 | 62 | [discrete] 63 | ==== Input Manifest format 64 | 65 | The input manifest contains a list of files to include in this backup set. 66 | The format is a delimited list of file names and file metadata, with the following fields: 67 | .BP 68 | 69 | 70 | *1 - FType*:: 71 | Values are one of "f", "d", "l", "c", "b" 72 | 73 | *2 - Mode*:: 74 | File mode in octal 75 | 76 | *3 - Device*:: 77 | Device number of file system 78 | 79 | *4 - Inode*:: 80 | Inode number of file 81 | 82 | *5 - UName*:: 83 | User name 84 | 85 | *6 - UID*:: 86 | User ID number 87 | 88 | *7 - GName*:: 89 | User's Group Name 90 | 91 | *8 - GID*:: 92 | User's Group Number 93 | 94 | *9 - Size*:: 95 | File size in bytes 96 | 97 | *10 - Hash*:: 98 | File Hash (future use, set to "0") 99 | 100 | *11 - CTime*:: 101 | File Inode's last change time 102 | 103 | *12 - MTime*:: 104 | File Content's last modififed time 105 | 106 | *13 - Path*:: 107 | Full file path 108 | 109 | *14 - LTarget*:: 110 | Link target 111 | 112 | Field 14 (Link Target) is only present if the file type is "l" (symbolic link). 113 | 114 | The fields are tab-delimited. If the "--null" option is specified, then each line is null terminated, with an additional null character delimiting fields 13 and 14. Otherwise if "--not-null" is specified, fields 13 and 14 are tab delimited, and the path names must have special characters escaped. 115 | 116 | The input manifest can be created with the GNU _find_ command, with the following print formatting specification (suitable for the "--null" flag): 117 | 118 | .EX 119 | find [ parameters ] \( -type f -o -type d \ .br 120 | -printf "%y\t%#m\t%D\t%i\t%u\t%U\t%g\t%G\t%s\t0\t%C@\t%T@\t%p\0" .br 121 | -o -type l -printf "%y\t%#m\t%D\t%i\t%u\t%U\t%g\t%G\t%s\t0\t%C@\t%T@\t%p\0%l\0" 122 | .EE 123 | 124 | [discrete] 125 | ==== Returned Snapshot manifest output 126 | 127 | The manifest returned is either a null-delimited list of files (if "--null-output" is specified), 128 | or a newline-delimited list of files with special characters escaped (if "--not-null-output is specified). 129 | This is the list of files that are required to complete the snapshot (any file that hasn't changed from previous backups will be referenced from the backup server). This list is suitable for passing into the _tar_ command. 130 | 131 | ==== See Also 132 | 133 | *snebu*(1), 134 | *snebu-submitfiles*(1), 135 | *snebu-restore*(1), 136 | *snebu-listbackups*(1), 137 | *snebu-expire*(1), 138 | *snebu-purge*(1), 139 | *snebu-permissions*(1), 140 | *snebu-client*(1) 141 | -------------------------------------------------------------------------------- /docs/snebu-permissions.1: -------------------------------------------------------------------------------- 1 | .TH SNEBU-PERMISSIONS "1" "December 2020" "snebu-permissions" "User Commands" 2 | .na 3 | .SH NAME 4 | snebu permissions \- Set permissions for Snebu when used in multi-user mode 5 | .SH SYNOPSIS 6 | .B snebu 7 | \fBpermissions\fR 8 | [ \fB-l\fR | \fB-a\fR | \fB-r\fR ] 9 | \fB-c\fR \fIcommand\fR 10 | \fB-n\fR \fIhostname\fR 11 | \fB-u\fR \fIuser\fR 12 | .SH DESCRIPTION 13 | .TP 14 | The \fIpermissions\fR command lists, adds, or removes user permissions. 15 | These permissions are applied when the "snebu" command is installed setuid, and run 16 | by a OS different user. 17 | .SH OPTIONS 18 | .TP 19 | \fB\-l\fR, \fB\-\-list\fR 20 | Lists all installed permissions. If the \fB\-c\fR, \fB\-n\fR, or 21 | \fB\-u\fR options are given, this list is restricted to 22 | those sub commands, hostnames, or users respectively. 23 | .TP 24 | \fB\-a\fR, \fB\-\-add\fR 25 | Adds permissions for the specified sub command [\-c], 26 | hostname [\-n], and user [\-u]. 27 | .TP 28 | \fB\-r\fR, \fB\-\-remove\fR 29 | Removes permissions for the specified sub command 30 | [\-c], hostname [\-n], and user [\-u]. 31 | .TP 32 | \fB\-c\fR, \fB\-\-command\fR \fIsub command\fR 33 | The sub command that this permission command applies to. 34 | .TP 35 | \fB\-n\fR, \fB\-\-name\fR \fIhostname\fR 36 | The host name that this permission command applies to. 37 | .TP 38 | \fB\-u\fR, \fB\-\-user\fR \fIusername\fR 39 | The user that this permission command applies to. 40 | .PP 41 | Available subcomands that work with permissions are: 42 | .RS 4 43 | .sp 44 | \fBbackup\fR (covers both newbackup and submitfiles functions) 45 | .sp 46 | \fBrestore\fR 47 | .sp 48 | \fBlistbackups\fR 49 | .sp 50 | \fBexpire\fR 51 | .sp 52 | \fBpurge\fR 53 | .sp 54 | \fBpermissions\fR 55 | .PP 56 | .RE 57 | Note that in the case of functions that aren't host specific (such as \fIpermissions\fR) or affect all hosts (\fIsnebu purge\fR, or \fIsnebu expire -a ...\fR), users will need to be granted permission to all hosts by specifying \fB-h '*'\fR in order to be granted access to those specific functions). 58 | .PP 59 | To grant permissions, this command must be run as the user that snebu is 60 | installed under, or the user must be granted access to the \fIpermissions\fR 61 | sub command 62 | .SH "SEE ALSO" 63 | .hy 0 64 | \fBsnebu\fR(1), 65 | \fBsnebu\-newbackup\fR(1), 66 | \fBsnebu\-submitfiles\fR(1), 67 | \fBsnebu\-restore\fR(1), 68 | \fBsnebu\-listbackups\fR(1), 69 | \fBsnebu\-expire\fR(1), 70 | \fBsnebu\-purge\fR(1), 71 | \fBsnebu\-client\fR(1) 72 | .PP 73 | -------------------------------------------------------------------------------- /docs/snebu-permissions_1.adoc: -------------------------------------------------------------------------------- 1 | === snebu-permissions(1) - Set permissions for Snebu when used in multi-user mode 2 | 3 | 4 | ---- 5 | snebu permissions [ -l | -a | -r ] -c command -n hostname -u user 6 | ---- 7 | 8 | ==== Description 9 | 10 | 11 | The _permissions_ command lists, adds, or removes user permissions.:: 12 | These permissions are applied when the "snebu" command is installed setuid, and run 13 | by a OS different user. 14 | 15 | ==== Options 16 | 17 | 18 | *-l*, *--list*:: 19 | Lists all installed permissions. If the *-c*, *-n*, or 20 | *-u* options are given, this list is restricted to 21 | those sub commands, hostnames, or users respectively. 22 | 23 | *-a*, *--add*:: 24 | Adds permissions for the specified sub command [-c], 25 | hostname [-n], and user [-u]. 26 | 27 | *-r*, *--remove*:: 28 | Removes permissions for the specified sub command 29 | [-c], hostname [-n], and user [-u]. 30 | 31 | *-c*, *--command* _sub command_:: 32 | The sub command that this permission command applies to. 33 | 34 | *-n*, *--name* _hostname_:: 35 | The host name that this permission command applies to. 36 | 37 | *-u*, *--user* _username_:: 38 | The user that this permission command applies to. 39 | 40 | Available subcomands that work with permissions are: 41 | 42 | *backup* (covers both newbackup and submitfiles functions) 43 | 44 | *restore* 45 | 46 | *listbackups* 47 | 48 | *expire* 49 | 50 | *purge* 51 | 52 | *permissions* 53 | 54 | Note that in the case of functions that aren't host specific (such as _permissions_) or affect all hosts (_snebu purge_, or _snebu expire -a ..._), users will need to be granted permission to all hosts by specifying *-h ${asterisk}* in order to be granted access to those specific functions). 55 | 56 | To grant permissions, this command must be run as the user that snebu is 57 | installed under, or the user must be granted access to the _permissions_ 58 | sub command 59 | 60 | ==== See Also 61 | 62 | *snebu*(1), 63 | *snebu-newbackup*(1), 64 | *snebu-submitfiles*(1), 65 | *snebu-restore*(1), 66 | *snebu-listbackups*(1), 67 | *snebu-expire*(1), 68 | *snebu-purge*(1), 69 | *snebu-client*(1) 70 | -------------------------------------------------------------------------------- /docs/snebu-purge.1: -------------------------------------------------------------------------------- 1 | .TH SNEBU-PURGE "1" "December 2020" "snebu-purge" "User Commands" 2 | .na 3 | .SH NAME 4 | snebu purge \- Remove backing files from expired backups 5 | .SH SYNOPSIS 6 | .B snebu 7 | \fBpurge\/\fB [ \fB-v\fR ] [ \fB-q\fR ] 8 | .SH DESCRIPTION 9 | Permanently removes files from disk storage that are no longer 10 | referenced by any backups. Run this command after running "snebu expire". 11 | .SH OPTIONS 12 | .TP 13 | \fB\-v\fR, \fB\-\-verbose\fR 14 | Turns on verbose mode (default if stderr is a tty) 15 | .TP 16 | \fB\-q\fR, \fB\-\-quiet\fR 17 | Turns off verbose mode (default if stderr is not a tty) 18 | .SH "SEE ALSO" 19 | .hy 0 20 | \fBsnebu\fR(1), 21 | \fBsnebu\-newbackup\fR(1), 22 | \fBsnebu\-submitfiles\fR(1), 23 | \fBsnebu\-restore\fR(1), 24 | \fBsnebu\-listbackups\fR(1), 25 | \fBsnebu\-expire\fR(1), 26 | \fBsnebu\-permissions\fR(1), 27 | \fBsnebu\-client\fR(1) 28 | .PP 29 | -------------------------------------------------------------------------------- /docs/snebu-purge_1.adoc: -------------------------------------------------------------------------------- 1 | === snebu-purge(1) - Remove backing files from expired backups 2 | 3 | 4 | ---- 5 | snebu purge [ -v ] [ -q ] 6 | ---- 7 | 8 | ==== Description 9 | 10 | Permanently removes files from disk storage that are no longer 11 | referenced by any backups. Run this command after running "snebu expire". 12 | 13 | ==== Options 14 | 15 | 16 | *-v*, *--verbose*:: 17 | Turns on verbose mode (default if stderr is a tty) 18 | 19 | *-q*, *--quiet*:: 20 | Turns off verbose mode (default if stderr is not a tty) 21 | 22 | ==== See Also 23 | 24 | *snebu*(1), 25 | *snebu-newbackup*(1), 26 | *snebu-submitfiles*(1), 27 | *snebu-restore*(1), 28 | *snebu-listbackups*(1), 29 | *snebu-expire*(1), 30 | *snebu-permissions*(1), 31 | *snebu-client*(1) 32 | -------------------------------------------------------------------------------- /docs/snebu-quickstart.adoc: -------------------------------------------------------------------------------- 1 | == Quick start 2 | 3 | === Compiling / Installation 4 | 5 | tar -zxvf snebu-1.1.0.tar.gz 6 | make 7 | sudo make install 8 | 9 | Then to set up privilege separation: 10 | 11 | sudo useradd -r -U -d /var/lib/snebu snebu 12 | sudo chown snebu:snebu 13 | 14 | This creates a user and group called "snebu", installing the snebu binary as SUID to user "snebu". The config file /etc/sneub.conf defaults to placing the vault in `/var/lib/snebu/vault` and the backup catalog DB in `/var/lib/snebu/catalog`. The `vault` directory is where the backed up files are stored, and the `catalog` directory holds the backup catalog database (in SQLite format). 15 | 16 | You can mount an external storage device on /var/lib/snebu (making sure the `snebu` user/group owns the directory after mounting -- if not, `chown snebu:snebu /var/lib/snebu/` once the drive is mounted). However, if the storage device has slow seek times, which is the case with many 2.5" USB-powered mechanical hard drives, then you will get better performance by mounting the mechanical drive under `/var/lib/snebu/vault`, and mounting a separate SSD drive in `/var/lib/snebu/catalog` (or the appropriate directories specified in `/etc/snebu.conf`. Or if you keep the `catalog` directory on the local systems drive then be sure to separately copy the contents of the catalog directory to the external storage device after a backup session finishes. 17 | 18 | === Sample Backup and Restore Operation 19 | 20 | ==== User and permissions setup 21 | You will need to set up user permissions for any user ID that access the `snebu` binary. To set up permissions for the `root` user, run the following commands: 22 | 23 | ---- 24 | $ sudo -u snebu snebu permissions --add --command '*' --name '*' --user root 25 | ---- 26 | 27 | If a user other than root needs to run snebu, then they need to be added to the snebu group. 28 | 29 | ==== Run a backup 30 | `sudo` is needed here to allow snebu-client to read all the files on the host. If a user is only backing up their own directory then sudo isn't needed, and they can be given more granular permissions to the `snebu` command -- see the man page snebu-permissions(1). 31 | ---- 32 | $ sudo snebu-client backup 33 | ---- 34 | 35 | This backs up all mounted disk-based file systems (automatically skips tmpfs, procfs, sysfs, and other "nodev" mount points). The backup name defaults to the host name of the client, however this can be overridden with `--name` parameter. You can also follow the command with a file or path list. For example: 36 | 37 | ---- 38 | $ sudo snebu-client backup -n boss-home-dir /home/bigboss 39 | ---- 40 | 41 | ==== List backups, contents, and restore a file 42 | ---- 43 | $ sudo snebu-client listbackups -v 44 | 45 | bosshost1 46 | 1608761077 / daily / Wed Dec 23 16:04:37 2020 47 | ---- 48 | ---- 49 | $ sudo snebu-client listbackups -n bosshost1 -d 1608761077 '*BudgetProposal*' 50 | 51 | /home/bigboss/BudgetProposal2021.doc 52 | ---- 53 | ---- 54 | $ sudo snebu-client restore -n bosshost1 -d 1608761077 -C /tmp \ 55 | --graft /home/bigboss/=bigboss-restored 56 | 57 | bigboss-restored/BudgetProposal2021.doc 58 | ---- 59 | 60 | The first command gives a list of all hosts that have been backed up. With the "-v" flag, it will also give all backup sets that are part of each backed up host. Backup sets are identified by a serial number, which is the time/date that the backup was created, represented in Unix time_t format (i.e., the number of seconds since Jan 1, 1970). 61 | 62 | The second command will list the files that are part of the host and backup set, restricting the output to the given file specification. 63 | 64 | In the third command, a restore of this backup set is initiated. The client changes to the "/tmp" directory, so everything restored is relative to this directory (or specify `-C /` to restore to the original location). The `--graft` parameter is specified to re-write part of the file path -- in this case it replaces the directory "/home/bigboss/" with "bigboss-restored". Putting it together the final path file that gets restored is in `/tmp/bigobss-restored/BudgetProposal2021.doc`. 65 | 66 | Notice that the backup above is a "daily" backup -- this is the retention schedule that this backup set is assigned to. By default, backups ran on Sunday through Friaday are `daily` backups, Saturday is a `weekly` backup, and the first of the month is a `monthly` backup. 67 | 68 | ==== Remote backups 69 | If snebu is installed in a remote backup server called `bkupsvr1`, and you have the snebu-client script on a local host, you can add the parameters `--backup-server bkupsvr1` and `--backup-user svc-bosshost1` to the above commands. Make sure to create the service user account `svc-bosshost1` on the remote host (or whichever user account name specified by your organizations practices), along with adding the account to the snebu group. Set up ssh key based authentication for unattended backups, and then create the appropriate permissions for this service user on the remote backup server: 70 | 71 | admin@bkupsvr1:~$ sudo -u snebu snebu permissions --add --command '*' \ 72 | --name 'bosshost1' --user svc-bosshost1 73 | 74 | Now you can back up to this host: 75 | 76 | root@booshost1:~$ sudo snebu-client backup --backup-server bkupsvr1 --backup-user svc-bosshost1 77 | 78 | Note, you may wish to grant more granular permissions such as "backup", "listbackups" and "restore" in the above `snebu permissions` command. This would prevent the client from deleting backups on the backup server if it were to become compromised. See the `snebu-permissions` man page for detailed command usage. 79 | 80 | If you want more protection, you can reverse the process and have the remote backup server "pull" a backup from the client: 81 | 82 | snebu@bkupsvr1:~$ snebu-client backup --remote-client bosshost1 \ 83 | --remote-user root --sudo svs-backup 84 | 85 | This will access bosshost1 as the service user `svs-backup`, then sudo to `root` to pull the data. Make sure to set up ssh key authentication between `snebu@bkupsvr1` and `svs-backup@bosshost1`. If you leave off the `--sudo` flag, then the user `root` will be directly accessed via ssh (requiring ssh key authorization to `root@bosshost1`) 86 | 87 | 88 | ==== Expiring old backups 89 | 90 | Run the following on the backup server to expire old backups 91 | ---- 92 | $ sudo snebu expire -a 14 -r daily 93 | $ sudo snebu exipre -a 42 -r weekly 94 | $ sudo snebu expire -a 365 -r monthly 95 | $ sudo snebu purge 96 | ---- 97 | 98 | This expires all daily backups older than 2 weeks, weekly backups older than 6 weeks, and monthly backups older than a year. Expiring a backup only removes the metadata, and takes a short amount of time. A `purge` permanently remove data from the `vault`, and can take a bit longer (depending on the number of files that need to be removed). 99 | 100 | In the above example, the commands were run under the user ID `snebu`, which owns the repository and has all permissions. Again, you can grant a specific user permission to run the expire and purge commands to limit the need to access the main user account (see _snebu-permissions(1)_ documentation). 101 | 102 | ==== Encryption 103 | Snebu supports client-side public key encryption. This requires the program `tarcrypt` to be installed on the client. On the client, run the command `tarcrypt genkey -f outputfile`, and make sure it has appropriate permissions and ownership 104 | 105 | $ sudo tarcrypt genkey -f /etc/snebu-backup.key 106 | $ sudo chown root:root /etc/snebu-backup.key 107 | $ sudo chmod 600 /etc/snebu-backup.key 108 | 109 | You will be prompted for a passphrase to protect the private key stored in the `.key` file. Then, on any of the backup command variations, add the parameter `--encryption-key /etc/snebu-backup.key`: 110 | 111 | sudo snebu-client backup --backup-server bkupsvr1 --backup-user svc-bosshost1 \ 112 | --encryption-key /etc/snebu-backup.key 113 | 114 | Note, you can repeate the `--encryption-key` parameter to encrypt with multiple keys -- in this case, the passphrase for any one of the keys can be used to decode the backup upon restoring. 115 | 116 | When restoring an encrypted backup, specify `snebu-client restore --decrypt` along with the other parameters as appropriate. No key file is specified, as all key data is securely stored with the backup. You will be prompted for the private key passphrase for one of the keys when restoring. 117 | -------------------------------------------------------------------------------- /docs/snebu-reference.adoc: -------------------------------------------------------------------------------- 1 | == Reference 2 | 3 | include::snebu-client_1.adoc[] 4 | 5 | include::snebu-client-backup_1.adoc[] 6 | 7 | include::snebu-client-listbackups_1.adoc[] 8 | 9 | include::snebu-client-validate_1.adoc[] 10 | 11 | include::snebu-client-restore_1.adoc[] 12 | 13 | include::snebu-client.conf_5.adoc[] 14 | 15 | include::snebu-client-plugin_5.adoc[] 16 | 17 | include::snebu_1.adoc[] 18 | 19 | include::snebu-newbackup_1.adoc[] 20 | 21 | include::snebu-submitfiles_1.adoc[] 22 | 23 | include::snebu-listbackups_1.adoc[] 24 | 25 | include::snebu-restore_1.adoc[] 26 | 27 | include::snebu-expire_1.adoc[] 28 | 29 | include::snebu-purge_1.adoc[] 30 | 31 | include::snebu-permissions_1.adoc[] 32 | 33 | include::tarcrypt_1.adoc[] 34 | -------------------------------------------------------------------------------- /docs/snebu-restore.1: -------------------------------------------------------------------------------- 1 | .TH SNEBU-RESTORE "1" "December 2020" "snebu-restore" "User Commands" 2 | .na 3 | .SH NAME 4 | snebu restore \- Generates tar file from backup 5 | .SH SYNOPSIS 6 | .B snebu 7 | \fBrestore\fR \fB-n\fR \fIbackupname\fR 8 | \fB-d\fR \fIdatestamp\fR 9 | [ \fIfile_list\fR... ] 10 | .SH DESCRIPTION 11 | Generates a tar file containing files from a given backup set. 12 | Pipe the output of this command into \fItar\fR to restore files. 13 | .SH OPTIONS 14 | .TP 15 | \fB\-n\fR, \fB\-\-name\fR \fIbackupname\fR 16 | Name of the backup, as specified in the \fInewbackup\fR subcommand. 17 | Typically is the name of the server that was backed up. 18 | .TP 19 | \fB\-d\fR, \fB\-\-date\fR \fIdatestamp\fR 20 | Date stamp for this backup set. The format is in 21 | time_t format, sames as the output of the "date\~+%s" command. 22 | .TP 23 | \fB\-\-graft\fR \fI/path/name/\fR\fB=\fR\fI/new/name/\fR 24 | Re\-write path names beginning with "\fI/path/name/\fR" to "\fI/new/name/\fR". 25 | This allows you to restore a file to a different location. 26 | .TP 27 | [ \fIfile\-list\fR ] 28 | List of files to restore. Defaults to all. 29 | .SH "SEE ALSO" 30 | .hy 0 31 | \fBsnebu\fR(1), 32 | \fBsnebu\-newbackup\fR(1), 33 | \fBsnebu\-submitfiles\fR(1), 34 | \fBsnebu\-listbackups\fR(1), 35 | \fBsnebu\-expire\fR(1), 36 | \fBsnebu\-purge\fR(1), 37 | \fBsnebu\-permissions\fR(1), 38 | \fBsnebu\-client\fR(1) 39 | .PP 40 | -------------------------------------------------------------------------------- /docs/snebu-restore_1.adoc: -------------------------------------------------------------------------------- 1 | === snebu-restore(1) - Generates tar file from backup 2 | 3 | 4 | ---- 5 | snebu restore -n backupname -d datestamp [ file_list... ] 6 | ---- 7 | 8 | ==== Description 9 | 10 | Generates a tar file containing files from a given backup set. 11 | Pipe the output of this command into _tar_ to restore files. 12 | 13 | ==== Options 14 | 15 | 16 | *-n*, *--name* _backupname_:: 17 | Name of the backup, as specified in the _newbackup_ subcommand. 18 | Typically is the name of the server that was backed up. 19 | 20 | *-d*, *--date* _datestamp_:: 21 | Date stamp for this backup set. The format is in 22 | time_t format, sames as the output of the "date +%s" command. 23 | 24 | *--graft* _/path/name/_*=*_/new/name/_:: 25 | Re-write path names beginning with "_/path/name/_" to "_/new/name/_". 26 | This allows you to restore a file to a different location. 27 | 28 | [ _file-list_ ]:: 29 | List of files to restore. Defaults to all. 30 | 31 | ==== See Also 32 | 33 | *snebu*(1), 34 | *snebu-newbackup*(1), 35 | *snebu-submitfiles*(1), 36 | *snebu-listbackups*(1), 37 | *snebu-expire*(1), 38 | *snebu-purge*(1), 39 | *snebu-permissions*(1), 40 | *snebu-client*(1) 41 | -------------------------------------------------------------------------------- /docs/snebu-submitfiles.1: -------------------------------------------------------------------------------- 1 | .TH SNEBU-SUBMITFILES "1" "December 2020" "snebu-submitfiles" "User Commands" 2 | .na 3 | .SH NAME 4 | snebu submitfiles \- Recieves tar file contents to complete a backup 5 | .SH SYNOPSIS 6 | .B snebu 7 | \fBsubmitfiles\fR 8 | \fB-n\fR \fIbackupname\fR 9 | \fB-d\fR \fIdatestamp\fR 10 | .SH DESCRIPTION 11 | The "submitfiles" sub command is called after running \fIsnebu\~newbackup\fR, 12 | and is used to submit a tar file containing the files from the snapshot manifest returned by \fInewbackup\fR. 13 | .SH OPTIONS 14 | .TP 15 | \fB\-n\fR, \fB\-\-name\fR \fIbackupname\fR 16 | Name of the backup. 17 | Typically set to the server name that you are backing up. 18 | .TP 19 | \fB\-d\fR, \fB\-\-date\fR \fIdatestamp\fR 20 | Date stamp for this backup set. 21 | The format is in time_t format, sames as the output of the "date\~+%s" command. 22 | .TP 23 | \fB\-v\fR 24 | Verbose output 25 | .SH "SEE ALSO" 26 | .hy 0 27 | \fBsnebu\fR(1), 28 | \fBsnebu\-newbackup\fR(1), 29 | \fBsnebu\-restore\fR(1), 30 | \fBsnebu\-listbackups\fR(1), 31 | \fBsnebu\-expire\fR(1), 32 | \fBsnebu\-purge\fR(1), 33 | \fBsnebu\-permissions\fR(1), 34 | \fBsnebu\-client\fR(1) 35 | .PP 36 | -------------------------------------------------------------------------------- /docs/snebu-submitfiles_1.adoc: -------------------------------------------------------------------------------- 1 | === snebu-submitfiles(1) - Recieves tar file contents to complete a backup 2 | 3 | 4 | ---- 5 | snebu submitfiles -n backupname -d datestamp 6 | ---- 7 | 8 | ==== Description 9 | 10 | The "submitfiles" sub command is called after running _snebu newbackup_, 11 | and is used to submit a tar file containing the files from the snapshot manifest returned by _newbackup_. 12 | 13 | ==== Options 14 | 15 | 16 | *-n*, *--name* _backupname_:: 17 | Name of the backup. 18 | Typically set to the server name that you are backing up. 19 | 20 | *-d*, *--date* _datestamp_:: 21 | Date stamp for this backup set. 22 | The format is in time_t format, sames as the output of the "date +%s" command. 23 | 24 | *-v*:: 25 | Verbose output 26 | 27 | ==== See Also 28 | 29 | *snebu*(1), 30 | *snebu-newbackup*(1), 31 | *snebu-restore*(1), 32 | *snebu-listbackups*(1), 33 | *snebu-expire*(1), 34 | *snebu-purge*(1), 35 | *snebu-permissions*(1), 36 | *snebu-client*(1) 37 | -------------------------------------------------------------------------------- /docs/snebu.1: -------------------------------------------------------------------------------- 1 | .TH SNEBU "1" "December 2020" "snebu" "User Commands" 2 | .na 3 | .SH NAME 4 | snebu \- The simple network backup system 5 | .SH SYNOPSIS 6 | .B snebu 7 | [ \fB-c\fR | \fB--config\fR \fIfilepath\fR ] 8 | \fIsubcommand \/\fR[ \fIoptions \/\fR] 9 | .SH DESCRIPTION 10 | The \fIsnebu\fR command is a backup tool which manages storing data from 11 | backup sessions on disk-based storage, utilizing a simple database 12 | for tracking backup sets and meta data. With the exception of administrative 13 | sub commands (expire, purge, permissions), it is typically it is called via a 14 | front end script (such as the included "snebu-client" shell script). 15 | The subcommands are listed below along with the most common options. 16 | Details on each command are given in each command's individual man page. 17 | 18 | .SS "Sub commands are as follows:" 19 | .TP 20 | \fBnewbackup\fR \fB\-n\fR \fIbackupname\fR \fB\-d\fR \fIdatestamp\fR \fB\-r\fR \fIschedule\fR 21 | Initiates a new backup set, taking in the full backup manifest, 22 | returning a snapshot manifest. 23 | .TP 24 | \fBsubmitfiles\fR \fB\-n\fR \fIbackupname\fR \fB\-d\fR \fIdatestamp\fR 25 | Receives a backup in TAR format that fulfills the snapshot manifest returned from newbackup 26 | .TP 27 | \fBrestore\fR \fB\-n\fR \fIbackupname\fR \fB\-d\fR \fIdatestamp\fR [ \fIfile_list...\fR ] 28 | Generates a tar file containing the specified backup set. 29 | .TP 30 | \fBlistbackups\fR [ \fB\-n\fR \fIbackupname\fR [ \fB\-d\fR \fIdatestamp\fR ]] [ \fIfile_list...\fR ] 31 | List backed up hosts, backup sets within a host, or files within a backup set. 32 | .TP 33 | \fBexpire\fR [ \fB\-n\fR \fIbackupname\fR \fB\-d\fR \fIdatestamp\fR ] or [ \fB\-a\fR \fIdays\fR \fB\-r\fR \fIschedule\fR [ \fB-n\fR \fIhostname\fR ]] 34 | Expires (removes) the given backup set, or backups matching the given criteria 35 | .TP 36 | \fBpurge\fR 37 | Purges backing files from the vault that are part of expired backups 38 | .TP 39 | \fBpermissions\fR 40 | [ \fB-l\fR | \fB-a\fR | \fB-r\fR ] 41 | \fB-c\fR \fIcommand\fR 42 | \fB-n\fR \fIhostname\fR 43 | \fB-u\fR \fIuser\fR 44 | Defines permissions for a given user, when snebu is run in multi-user mode. 45 | .TP 46 | \fBhelp\fR [subcommand] 47 | Displays help page of subcommand 48 | .SH "SEE ALSO" 49 | .hy 0 50 | \fBsnebu\-newbackup\fR(1), 51 | \fBsnebu\-submitfiles\fR(1), 52 | \fBsnebu\-restore\fR(1), 53 | \fBsnebu\-listbackups\fR(1), 54 | \fBsnebu\-expire\fR(1), 55 | \fBsnebu\-purge\fR(1), 56 | \fBsnebu\-permissions\fR(1), 57 | \fBsnebu-client\fR(1) 58 | .PP 59 | -------------------------------------------------------------------------------- /docs/snebu.adoc: -------------------------------------------------------------------------------- 1 | = SNEBU 2 | :sectnums: 3 | :sectnumlevels: 2 4 | :toc: left 5 | :toclevels: 2 6 | :keywords: Snebu, Linux Backup, Snapshot, Encrypting 7 | :nofooter: 8 | 9 | :asterisk: * 10 | ++++ 11 |
Simple Network Encrypting Backup Utility
12 | ++++ 13 | 14 | include::snebu-intro.adoc[] 15 | 16 | include::snebu-quickstart.adoc[] 17 | 18 | include::snebu-concepts.adoc[] 19 | 20 | include::snebu-reference.adoc[] 21 | -------------------------------------------------------------------------------- /docs/snebu_1.adoc: -------------------------------------------------------------------------------- 1 | === snebu(1) - The simple network backup system 2 | 3 | 4 | ---- 5 | snebu [ -c | --config filepath ] subcommand [ options ] 6 | ---- 7 | 8 | ==== Description 9 | 10 | The _snebu_ command is a backup tool which manages storing data from 11 | backup sessions on disk-based storage, utilizing a simple database 12 | for tracking backup sets and meta data. With the exception of administrative 13 | sub commands (expire, purge, permissions), it is typically it is called via a 14 | front end script (such as the included "snebu-client" shell script). 15 | The subcommands are listed below along with the most common options. 16 | Details on each command are given in each command's individual man page. 17 | 18 | [discrete] 19 | ==== Sub commands are as follows: 20 | 21 | 22 | *newbackup* *-n* _backupname_ *-d* _datestamp_ *-r* _schedule_:: 23 | Initiates a new backup set, taking in the full backup manifest, 24 | returning a snapshot manifest. 25 | 26 | *submitfiles* *-n* _backupname_ *-d* _datestamp_:: 27 | Receives a backup in TAR format that fulfills the snapshot manifest returned from newbackup 28 | 29 | *restore* *-n* _backupname_ *-d* _datestamp_ [ _file_list..._ ]:: 30 | Generates a tar file containing the specified backup set. 31 | 32 | *listbackups* [ *-n* _backupname_ [ *-d* _datestamp_ ]] [ _file_list..._ ]:: 33 | List backed up hosts, backup sets within a host, or files within a backup set. 34 | 35 | *expire* [ *-n* _backupname_ *-d* _datestamp_ ] or [ *-a* _days_ *-r* _schedule_ [ *-n* _hostname_ ]]:: 36 | Expires (removes) the given backup set, or backups matching the given criteria 37 | 38 | *purge*:: 39 | Purges backing files from the vault that are part of expired backups 40 | 41 | *permissions*:: 42 | [ *-l* | *-a* | *-r* ] 43 | *-c* _command_ 44 | *-n* _hostname_ 45 | *-u* _user_ 46 | Defines permissions for a given user, when snebu is run in multi-user mode. 47 | 48 | *help* [subcommand]:: 49 | Displays help page of subcommand 50 | 51 | ==== See Also 52 | 53 | *snebu-newbackup*(1), 54 | *snebu-submitfiles*(1), 55 | *snebu-restore*(1), 56 | *snebu-listbackups*(1), 57 | *snebu-expire*(1), 58 | *snebu-purge*(1), 59 | *snebu-permissions*(1), 60 | *snebu-client*(1) 61 | -------------------------------------------------------------------------------- /docs/tarcrypt.1: -------------------------------------------------------------------------------- 1 | .TH TARCRYPT "1" "December 2020" "tarcrypt" "User Commands" 2 | .na 3 | .SH NAME 4 | tarcrypt \- Compresses and encrypts file data in TAR files 5 | .SH SYNOPSIS 6 | .B tarcrypt 7 | \fBencrypt\fR \fB-k\fR \fIkeyfile\fR 8 | .sp 9 | .B tarcrypt 10 | \fBdecrypt\fR 11 | .sp 12 | .B tarcrypt 13 | \fBgenkey\fR \fB-f\fR \fIkeyfile\fR 14 | \fB-c\fR \fIcomment\fR 15 | .SH DESCRIPTION 16 | The \fItarcrypt\fR command acts as a filter for the \fItar\fR command. 17 | In encryption mode, it will compress and encrypt the data portion of TAR files 18 | while leaving header metadata intact. This allows the TAR file to be sent to 19 | a backup system that expects the Unix TAR format as input. 20 | .PP 21 | The key file that is generated by the \fIgenkey\fR function contains an encrypted 22 | (passphrase protected) RSA private key, public key, and HMAC key used for verification. 23 | The encrypted private key, public key, and a hash of the HMAC key are stored in 24 | the TAR file's global header. 25 | .PP 26 | Each individual file is encrypted with a random AES-256 key, which is in turn encrypted 27 | using the RSA public key. The file contents is also signed using the HMAC key, 28 | and the signature for the file is attached to the file header. 29 | .PP 30 | During a decrypt operation, the user is prompted for the passphrase protecting the private key, 31 | which is used to decrypt the AES key stored with each file. 32 | The passphrase, along with the public key hash, are used to re-create the secret HMAC key 33 | in order to validate each file contents as it is begin decrypted. 34 | .SH OPTIONS 35 | .TP 36 | \fBencrypt\fR 37 | Reads the tar command output on standard input, outputting an encrypted tar file. 38 | .RS 39 | \fBParameters\fR: 40 | .TP 41 | \fB-k\fR, \fB\-\-keyfile\fR \fIkeyfilename\fR 42 | Specifies the key file (generated by the \fIgenkey\fR subcommand) 43 | .sp 44 | Multiple key files may be specified by repeating this parameter. 45 | .RE 46 | .TP 47 | \fBdecrypt\fR 48 | Reads an encrypted tar file on standard input, prompts for the passphrase, 49 | decrypts and verifies contents outputting a standard tar file. 50 | .TP 51 | \fBgenkey\fR 52 | Generates a key file used by the \fIencrypt\fR function. 53 | .RS 54 | \fBParameters:\fR 55 | .TP 56 | \fB-f\fR, \fB\-\-filename\fR \fIkeyfilename\fR 57 | Specifies the filename to write the keyfile out to. 58 | .TP 59 | [ \fB-c\fR, \fB\-\-comment\fR "\fIcomment text\fR" ] 60 | Specifies a comment to include in the keyfile. 61 | .PP 62 | .SH SECURITY 63 | Public Key cryptography splits up a key into two parts -- an encryption (public) key, and a decryption (private) key. 64 | The public key isn't considered sensitive -- it is designed so that one party can send encrypted data to another party, 65 | by using the other party's public key. The private key, however, needs to be kept confidential by the receiving party. 66 | Typically the private key is stored encrypted with a symmetric algorithm (one where the same password is used to both encrypt 67 | and decrypt the data) to provide additional security. 68 | .PP 69 | In the case of tarcrypt, the sending and receiving party is the same entity, 70 | using a third party (the backup server) to store the encrypted data. 71 | If the backup is needed, chances are that the keyfile used to encrypt the backup is lost also. 72 | Therefore, both the public key (for reference), and an encrypted copy of the private key are stored 73 | in the generated encrypted tar file's global header. 74 | .PP 75 | For the purpose of file confidentiality the keyfile isn't considered sensitive, 76 | as the private key used to decrypt the data is stored in encrypted form. 77 | However, the keyfile also contains a secret HMAC key used to authenticate the contents of the encrypted 78 | tar file. Therefore if authenticity is needed, then the keyfile must be kept confidential 79 | (i.e., stored with appropriate file system permissions to be accessed only by the backup process). 80 | .SH NOTES 81 | The tarcrypt file format is an extension of the PAX TAR format, with custom values in the PAX header. 82 | If used in conjunction with a backup tool which expects the TAR format as input, 83 | then the backup tool may need some modifications in order to handle the extensions. 84 | If the tool stores the tar file intact, and if it doesn't choke on the custom header fields, 85 | then no modifications should be necessary. However if the backup system parses out the TAR file format 86 | (i.e., it if uses it as a serialization format), then it would need to be modified to store the encrypted 87 | header info along with the rest of the metadata, and re-generate the appropriate global and individual 88 | file headers. 89 | .PP 90 | -------------------------------------------------------------------------------- /docs/tarcrypt_1.adoc: -------------------------------------------------------------------------------- 1 | === tarcrypt(1) - Compresses and encrypts file data in TAR files 2 | 3 | 4 | ---- 5 | tarcrypt encrypt -k keyfile 6 | tarcrypt decrypt 7 | tarcrypt genkey -f keyfile -c comment 8 | ---- 9 | 10 | ==== Description 11 | 12 | The _tarcrypt_ command acts as a filter for the _tar_ command. 13 | In encryption mode, it will compress and encrypt the data portion of TAR files 14 | while leaving header metadata intact. This allows the TAR file to be sent to 15 | a backup system that expects the Unix TAR format as input. 16 | 17 | The key file that is generated by the _genkey_ function contains an encrypted 18 | (passphrase protected) RSA private key, public key, and HMAC key used for verification. 19 | The encrypted private key, public key, and a hash of the HMAC key are stored in 20 | the TAR file's global header. 21 | 22 | Each individual file is encrypted with a random AES-256 key, which is in turn encrypted 23 | using the RSA public key. The file contents is also signed using the HMAC key, 24 | and the signature for the file is attached to the file header. 25 | 26 | During a decrypt operation, the user is prompted for the passphrase protecting the private key, 27 | which is used to decrypt the AES key stored with each file. 28 | The passphrase, along with the public key hash, are used to re-create the secret HMAC key 29 | in order to validate each file contents as it is begin decrypted. 30 | 31 | ==== Options 32 | 33 | 34 | *encrypt*:: 35 | Reads the tar command output on standard input, outputting an encrypted tar file. 36 | *Parameters*: 37 | ** *-k*, *--keyfile* _keyfilename_ + 38 | Specifies the key file (generated by the _genkey_ subcommand) 39 | 40 | Multiple key files may be specified by repeating this parameter. 41 | 42 | 43 | *decrypt*:: 44 | Reads an encrypted tar file on standard input, prompts for the passphrase, 45 | decrypts and verifies contents outputting a standard tar file. 46 | 47 | *genkey*:: 48 | Generates a key file used by the _encrypt_ function. 49 | *Parameters:* 50 | ** *-f*, *--filename* _keyfilename_ + 51 | Specifies the filename to write the keyfile out to. 52 | ** [ *-c*, *--comment* "_comment text_" ] + 53 | Specifies a comment to include in the keyfile. 54 | 55 | ==== Security 56 | 57 | Public Key cryptography splits up a key into two parts -- an encryption (public) key, and a decryption (private) key. 58 | The public key isn't considered sensitive -- it is designed so that one party can send encrypted data to another party, 59 | by using the other party's public key. The private key, however, needs to be kept confidential by the receiving party. 60 | Typically the private key is stored encrypted with a symmetric algorithm (one where the same password is used to both encrypt 61 | and decrypt the data) to provide additional security. 62 | 63 | In the case of tarcrypt, the sending and receiving party is the same entity, 64 | using a third party (the backup server) to store the encrypted data. 65 | If the backup is needed, chances are that the keyfile used to encrypt the backup is lost also. 66 | Therefore, both the public key (for reference), and an encrypted copy of the private key are stored 67 | in the generated encrypted tar file's global header. 68 | 69 | For the purpose of file confidentiality the keyfile isn't considered sensitive, 70 | as the private key used to decrypt the data is stored in encrypted form. 71 | However, the keyfile also contains a secret HMAC key used to authenticate the contents of the encrypted 72 | tar file. Therefore if authenticity is needed, then the keyfile must be kept confidential 73 | (i.e., stored with appropriate file system permissions to be accessed only by the backup process). 74 | 75 | ==== Notes 76 | 77 | The tarcrypt file format is an extension of the PAX TAR format, with custom values in the PAX header. 78 | If used in conjunction with a backup tool which expects the TAR format as input, 79 | then the backup tool may need some modifications in order to handle the extensions. 80 | If the tool stores the tar file intact, and if it doesn't choke on the custom header fields, 81 | then no modifications should be necessary. However if the backup system parses out the TAR file format 82 | (i.e., it if uses it as a serialization format), then it would need to be modified to store the encrypted 83 | header info along with the rest of the metadata, and re-generate the appropriate global and individual 84 | file headers. 85 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | docs/readme.md -------------------------------------------------------------------------------- /snebu-client-db-plugin-template: -------------------------------------------------------------------------------- 1 | ### Snebu backup plugin template for databases 2 | [ -z "${verbose}" ] && verbose=0 3 | [ "${verbose}" -gt 0 ] && echo "Executing client plugin template" >&2 4 | 5 | pluginpre=pluginpref 6 | pluginpost=pluginpostf 7 | # Initialize an internal housekeeping variable 8 | # (Step 0) 9 | dbstage=0 10 | 11 | # Define the pre-backup script 12 | pluginpref() { 13 | [ "${verbose}" -gt 0 ] && echo "Executing client plugin pre script" >&2 14 | # Stage 0 => haven't backed up the DB yet 15 | if [ "${dbstage}" = 0 ] 16 | then 17 | # (Step 1) 18 | # Save the current include/exclude list 19 | OLD_INCLUDE=( "${INCLUDE[@]}" ) 20 | OLD_EXCLUDE=( "${EXCLUDE[@]}" ) 21 | OLD_EXCLUDEMATCH=( "${EXCLUDEMATCH[@]}" ) 22 | 23 | # Zero out exclude list 24 | EXCLUDE=( ) 25 | EXCLUDEMATCH=( ) 26 | 27 | # Set the include list to include database files 28 | DBF_FILES=( "$( 29 | # Function to list database filenames to standard output 30 | print_dbf_filenames 31 | )" ) 32 | INCLUDE=( "${DBF_FILES[@]}" ) 33 | 34 | # Place DB in hot backup mode 35 | begin_db_backup 36 | 37 | # After this, snebu-client-backup takes over and backs up 38 | # the above set include list. Then control jumps to 39 | # pluginpost() with dbstage still set to 0 40 | elif [ "${dbstage}" = 1 ] 41 | then 42 | # (Step 3) 43 | DBF_LOG_FILES=( "$( 44 | # Function to list archived transaction logs 45 | print_dbf_log_filenames 46 | )" ) 47 | INCLUDE=( "${DBF_LOG_FILES[@]}" ) 48 | 49 | # Back to the backup with the new include list, then 50 | # off to pluginpost again with dbstage set to 1 51 | fi 52 | } 53 | 54 | pluginpostf() { 55 | [ "${verbose}" -gt 0 ] && echo "client plugin post" >&2 56 | if [ "${dbstage}" = 0 ] 57 | then 58 | # (Step 2) 59 | # Take DB out of hot backup mode 60 | end_db_backup 61 | 62 | # Define the next stage, and repeat the backup 63 | dbstage=1 64 | bkrepeat=1 65 | 66 | # Now control jumps back to pluginpre() with dbstage=1 67 | elif [ "${dbstage}" = 1 ] 68 | then 69 | # (Step 4) 70 | # Restore the original include/exclude list, with the 71 | # database files added to the exclude list. 72 | INCLUDE=( "${OLD_INCLUDE[@]}" ) 73 | EXCLUDE=( "${OLD_EXCLUDE[@]}" "${DBF_FILES[@]}" "${DBF_LOG_FILES[@]}" ) 74 | EXCLUDEMATCH=( "${OLD_EXCLUDEMATCH[@]}" ) 75 | 76 | # Define the next stage, and repeat the backup 77 | dbstage=2 78 | bkrepeat=1 79 | 80 | # Control jumps back to pluginpre(), however no more pre- 81 | # processing is needed for stage 2, so the backup begins 82 | # again with the original client include/exclude (plus the 83 | # above database files added to the exclude). 84 | elif [ "${dbstage}" = 2 ] 85 | then 86 | # (Step 5) 87 | # Break the cycle, backup is completed for this host. 88 | bkrepeat=0 89 | fi 90 | } 91 | 92 | # Also, don't forget to fill in the functions referenced above: 93 | 94 | begin_db_backup() { 95 | [ "${verbose}" -gt 0 ] && echo "Begin DB backup" >&2 96 | ### Steps to place DB in hot backup mode 97 | ### Make sure to execute these on the target host being backed 98 | ### up if running from the backup server (in pull mode) 99 | 100 | } 101 | 102 | end_db_backup() { 103 | [ "${verbose}" -gt 0 ] && echo "End DB backup" >&2 104 | ### Steps to DB out of hot backup mode 105 | ### Make sure to execute these on the target host being backed 106 | ### up if running from the backup server (in pull mode) 107 | } 108 | 109 | print_dbf_filenames() { 110 | [ "${verbose}" -gt 0 ] && echo "Generating DBF filenames" >&2 111 | ### Output list of dbf file names 112 | ### Make sure to execute these on the target host being backed 113 | ### up if running from the backup server (in pull mode) 114 | } 115 | 116 | print_dbf_log_filenames() { 117 | [ "${verbose}" -gt 0 ] && echo "Generating DBF log filenames" >&2 118 | ### Output list of archived transaction log file names 119 | ### Make sure to execute these on the target host being backed 120 | ### up if running from the backup server (in pull mode) 121 | } 122 | -------------------------------------------------------------------------------- /snebu-expire-purge.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2009 - 2021 Derek Pressnall 2 | * 3 | * This file is part of Snebu, the Simple Network Encrypting Backup Utility 4 | * 5 | * Snebu is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License Version 3 7 | * as published by the Free Software Foundation. 8 | * 9 | * Snebu is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Snebu. If not, see