Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
deploy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
paradise
deploy
Commits
fd591aed
There was an error fetching the commit references. Please try again later.
Commit
fd591aed
authored
5 years ago
by
root
Browse files
Options
Downloads
Patches
Plain Diff
Add a new backup script
parent
e5a9f5ef
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
backup-tar/backup.sh
+40
-0
40 additions, 0 deletions
backup-tar/backup.sh
backup-tar/init.sh
+9
-0
9 additions, 0 deletions
backup-tar/init.sh
with
49 additions
and
0 deletions
backup-tar/backup.sh
0 → 100755
+
40
−
0
View file @
fd591aed
#!/usr/bin/env bash
set
-e
fail
()
{
echo
"
$1
"
>
&2
exit
1
}
[[
"
$1
"
=
"full"
]]
||
[[
"
$1
"
=
"weekly"
]]
||
[[
"
$1
"
=
"daily"
]]
||
\
fail
"usage:
$0
[full|weekly|daily]"
TARGET
=
backup-
$HOSTNAME
@antea
LOCAL_HOME_ID
=
$(
stat
-c
%d /home
)
SOURCES
=
$(
comm
-12
<
(
getent passwd |
cut
-d
:
-f6
|
sort
)
<
(
for
i
in
/home/
*
;
do
[[
$(
stat
-c
%d
$i
)
-eq
$LOCAL_HOME_ID
]]
&&
echo
$i
;
done
)
)
TYPE
=
$1
TIMESTAMP
=
$(
date
+
"%Y-%m-%d"
)
BACKUP_FILE
=
${
TYPE
}
/
${
TIMESTAMP
}
.tar.xz
INCFILE_TGT
=
${
TYPE
}
/
${
TIMESTAMP
}
.snar
INCFILE
=
${
TIMESTAMP
}
.
${
TYPE
}
.snar
INC_FILTER
=
"."
if
[[
"
$TYPE
"
=
"weekly"
]]
;
then
INCFILE
=
'\(full\|weekly\)'
fi
[[
-f
$INCFILE
]]
&&
fail
"ERROR: backup already in progress (incremental backup file exists)"
if
[[
"
$TYPE
"
!=
"full"
]]
;
then
LAST
=
$(
ls
*
.snar |
sort
|
grep
$INC_FILTER
|
tail
-n1
)
if
[[
-f
"
$LAST
"
]]
;
then
cp
--reflink
=
auto
$LAST
$INCFILE
fi
fi
set
-x
ssh
$TARGET
"mkdir -p
$TYPE
"
tar
--create
--xz
--xattrs
--acls
--listed-incremental
=
$INCFILE
$SOURCES
| ssh
$TARGET
"cat >
$BACKUP_FILE
"
scp
$INCFILE
$TARGET
:
$INCFILE_TGT
This diff is collapsed.
Click to expand it.
backup-tar/init.sh
0 → 100755
+
9
−
0
View file @
fd591aed
#!/usr/bin/env bash
set
-ex
KEY
=
$HOME
/.ssh/id_rsa
PUB
=
${
KEY
}
.pub
test
-f
$KEY
&&
exit
1
ssh-keygen
-b
4096
-t
rsa
-N
""
-f
$KEY
echo
"Add the following to /backup-tar/
$HOSTNAME
/.ssh/authorized_keys on the backup server:"
cat
$PUB
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