Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
backupninja
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
raT
backupninja
Commits
2e6d94d8
Commit
2e6d94d8
authored
Jul 3, 2016
by
Benzhaomin
Committed by
Jérôme Charaoui
Jan 26, 2018
Browse files
Options
Downloads
Patches
Plain Diff
[borg] added borg handler and example straight from
@maethor
gists
parent
e0b43754
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/example.borg
+121
-0
121 additions, 0 deletions
examples/example.borg
handlers/borg
+120
-0
120 additions, 0 deletions
handlers/borg
with
241 additions
and
0 deletions
examples/example.borg
0 → 100644
+
121
−
0
View file @
2e6d94d8
##
## This is an example borgbackup configuration file.
##
## Here you can find all the possible borgbackup options, details of
## what the options provide and possible settings. The defaults are set
## as the commented out option, uncomment and change when
## necessary. Options which are uncommented in this example do not have
## defaults, and the settings provided are recommended.
##
## The defaults are useful in most cases, just make sure to configure the
## destination host and user.
##
## default is 0, but set to 19 if you want to lower the priority.
## an example setting would be:
## nicelevel = 19
##
## Default
# nicelevel = 0
## default is yes. set to no to skip the test if the remote host is alive
##
## Default:
# testconnect = no
######################################################
## source section
## (where the files to be backed up are coming from)
[source]
## how many days, weeks and months of data to keep
## for more info see : borg prune -h
##
## Default:
# keepdaily = 7
# keepweekly = 4
# keepmonthly = -1
## A few notes about includes and excludes:
## 1. include, exclude statements support globbing with '*'
## 2. Symlinks are not dereferenced. Moreover, an include line whose path
## contains, at any level, a symlink to a directory, will only have the
## symlink backed-up, not the target directory's content. Yes, you have to
## dereference yourself the symlinks, or to use 'mount --bind' instead.
## Example: let's say /home is a symlink to /mnt/crypt/home ; the following
## line will only backup a "/home" symlink ; neither /home/user nor
## /home/user/Mail will be backed-up :
## include = /home/user/Mail
## A workaround is to 'mount --bind /mnt/crypt/home /home' ; another one is to
## write :
## include = /mnt/crypt/home/user/Mail
## 3. All the excludes come after all the includes. The order is not otherwise
## taken into account.
## files to include in the backup
include = /opt
include = /srv
include = /etc
include = /root
include = /home
include = /usr/local
## files to exclude from the backup
include = /var
exclude = /var/lock
exclude = /var/run
exclude = /var/cache
exclude = /var/tmp
exclude = /var/lib/mongodb/journal
exclude = /var/lib/clamav
exclude = /var/lib/mlocate
exclude = /var/lib/postgresql
exclude = /var/lib/mysql
######################################################
## destination section
## (where the files are copied to)
[dest]
## put the backups under this directory, this must be set!
## an example setting would be:
## directory = /backups
##
## Default:
# directory =
## the machine which will receive the backups.
## an example setting would be:
## host = backuphost
##
## Default
# host =
## make the files owned by this user. you must be able to
## `su -c "ssh backupuser@backhost"` without specifying a password.
## an example setting would be:
## user = backupuser
##
## Default:
# user =
## archive name, should be unique every day.
## Format tags available :
## {now}, {utcnow}, {fqdn}, {hostname}, {user}, {pid}
## for more info see : borg create -h
##
## Default:
# archive = {now:%Y-%m-%d}
## compression algorithm
## can be "none", "lz4", "zlib", "zlib,0..zlib,9", "lzma", "lzma,0..lzma,9".
## - "none" stands for "no compression"
## - "lz4" is super fast, but low compression
## - "zlib" is less fast, but higher compression
## - "lzma" is even slower, even higher compression
## for more info see : borg create -h
##
## Default:
# compression = lz4
\ No newline at end of file
This diff is collapsed.
Click to expand it.
handlers/borg
0 → 100644
+
120
−
0
View file @
2e6d94d8
# -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
# vim: set filetype=sh sw=3 sts=3 expandtab autoindent:
#
# borg handler script for backupninja
# requires borgbackup
#
export
BORG_RELOCATED_REPO_ACCESS_IS_OK
=
yes
### GET CONFIG ###
getconf testconnect
yes
getconf nicelevel 0
setsection
source
getconf keepdaily 7
getconf keepweekly 4
getconf keepmonthly
-1
getconf include
getconf exclude
setsection dest
getconf user
getconf host
getconf directory
# strip trailing /
directory
=
${
directory
%/
}
getconf archive
{
now:%Y-%m-%d
}
getconf compression lz4
### CHECK CONFIG ###
# check the connection at the source and destination
[
-n
"
$test
"
]
||
test
=
0
if
[
"
$testconnect
"
=
"yes"
]
||
[
"
${
test
}
"
-eq
1
]
;
then
debug
"ssh -o PasswordAuthentication=no
$host
-l
$user
'echo -n 1'"
local
ret
=
`
ssh
-o
PasswordAuthentication
=
no
$host
-l
$user
'echo -n host is alive'
`
if
echo
$ret
|
grep
"host is alive"
;
then
debug
"Connected to
$host
as
$user
successfully"
else
fatal
"Can't connect to
$host
as
$user
."
fi
fi
# destination specific checks
[
"
$directory
"
!=
""
]
||
fatal
"Destination directory not set"
execstr_repository
=
"
$user
@
$host
:
$directory
"
execstr_archive
=
"
$archive
"
### INIT IF NEEDED ###
# :TODO:maethor:160509: Manage encryption
initstr
=
"borg init --encryption=none
$execstr_repository
"
debug
"
$initstr
"
output
=
"
`
su
-c
"
$initstr
"
2>&1
`
"
if
[
$?
=
2
]
;
then
debug
$output
info
"Repository was already initialized"
else
warning
$output
warning
"Repository has been initialized"
fi
### EXECUTE ###
execstr
=
"borg create --stats --compression
$compression
"
set
-o
noglob
# includes
SAVEIFS
=
$IFS
IFS
=
$(
echo
-en
"
\n\b
"
)
for
i
in
$include
;
do
includes
=
"
${
includes
}
'
$i
'"
done
IFS
=
$SAVEIFS
# excludes
SAVEIFS
=
$IFS
IFS
=
$(
echo
-en
"
\n\b
"
)
for
i
in
$exclude
;
do
excludes
=
"
${
excludes
}
--exclude '
$i
'"
done
IFS
=
$SAVEIFS
set
+o noglob
# include client-part and server-part
execstr
=
"
${
execstr
}
${
excludes
}
$execstr_repository
::
$execstr_archive
${
includes
}
"
debug
"
$execstr
"
if
[
$test
=
0
]
;
then
output
=
`
nice
-n
$nicelevel
su
-c
"
$execstr
"
2>&1
`
if
[
$?
=
0
]
;
then
debug
$output
info
"Successfully finished backing up source
$label
"
else
error
$output
fatal
"Failed backuping up source
$label
"
fi
fi
### REMOVE OLD BACKUPS ###
# borg prune
prunestr
=
"borg prune --keep-daily
$keepdaily
--keep-weekly
$keepweekly
--keep-monthly
$keepmonthly
$execstr_repository
"
debug
"
$prunestr
"
output
=
"
`
su
-c
"
$prunestr
"
2>&1
`
"
if
[
$?
=
0
]
;
then
debug
$output
info
"Removing old backups succeeded."
else
warning
$output
warning
"Failed removing old backups."
fi
return
0
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment