Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Michael Iseard
Backup Script
Commits
1d1561b4
Commit
1d1561b4
authored
Jul 31, 2019
by
Michael Iseard
Browse files
Initial commit
parents
Pipeline
#5
failed with stages
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
.env.sample
0 → 100644
View file @
1d1561b4
IM_BACKUP_SOURCE="/home/michael/docker/"
IM_BACKUP_DESTINATION="/nfs/usbdrive/"
IM_NFS_SOURCE="192.168.1.1:/media/usbdrive/"
BORG_PASSPHRASE="changeme"
\ No newline at end of file
backup.sh
0 → 100644
View file @
1d1561b4
#!/bin/bash
# VARIABLES
containers
=
$(
docker ps
-q
)
name
=
$(
date
+
"%Y%m%d"
)
done
=
$(
echo
-e
"
\e
[32mdone
\e
[0m"
)
fail
=
$(
echo
-e
"
\e
[31mfail
\e
[0m"
)
error
=
$(
echo
-e
"
\e
[31merror
\e
[0m"
)
dots
=
'....'
echo
"Starting backup - "
$name
>
$name
.log
# Prevent colour codes in log file
exec
>
>(
tee
>(
sed
's/\x1B\[[0-9;]*[JKmsu]//g'
>>
$name
.log
)
)
# LOAD ENVS
if
[
-f
".env"
]
;
then
export
$(
egrep
-v
'^#'
.env | xargs
)
>
/dev/null
else
echo
$error
".env file not found"
exit
1
fi
# FUNCTIONS
function
check_result
()
{
if
[
$?
-eq
0
]
;
then
echo
$done
else
echo
"
$fail
(exit code:
$?
)"
exit
1
fi
}
if
[[
!
-z
"
$IM_NFS_MOUNT_POINT
"
||
"
$IM_NFS_SOURCE
"
]]
;
then
echo
-n
'Mounting NFS.......'
$dots
sudo
mount
$IM_NFS_SOURCE
$IM_BACKUP_DESTINATION
check_result
fi
if
[
!
-z
"
$containers
"
]
;
then
echo
-n
'Stopping containers'
$dots
docker stop
$containers
>
/dev/null 2>&1
check_result
fi
echo
-n
'Sending backup.....'
$dots
borg create
$IM_BACKUP_DESTINATION
::
$name
$IM_BACKUP_SOURCE
check_result
echo
-n
'Pruning backups....'
$dots
borg prune
-sv
-d7
-w4
-m12
--show-rc
$IM_BACKUP_DESTINATION
>
/dev/null 2>&1
check_result
if
[[
!
-z
"
$IM_NFS_MOUNT_POINT
"
||
"
$IM_NFS_SOURCE
"
]]
;
then
echo
-n
'Unmounting backup..'
$dots
sudo
umount /nfs/BACKUP1/
check_result
fi
if
[
!
-z
"
$containers
"
]
;
then
echo
-n
'Starting containers'
$dots
docker start
$containers
>
/dev/null 2>&1
check_result
fi
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment