Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
backup
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Philipp Adolf
backup
Commits
fdd93406
Commit
fdd93406
authored
Aug 06, 2014
by
Philipp Adolf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial version
parents
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
81 additions
and
0 deletions
+81
-0
backup.sh
backup.sh
+81
-0
No files found.
backup.sh
0 → 100755
View file @
fdd93406
#!/usr/bin/env bash
declare
-r
basedir
=
"
${
HOME
}
/.backup"
declare
-r
lock
=
"
${
basedir
}
/lock"
declare
-ra
rsnapshotargs
=(
"-c"
"
${
HOME
}
/.rsnapshot.home.conf"
)
shopt
-s
nullglob
getoldest
()
{
local
-r
interval
=
"
$1
"
local
oldest
=
"-1"
current
=
""
dir
=
""
for
dir
in
"
${
basedir
}
/
${
interval
}
."
*
;
do
current
=
"
${
dir
##*.
}
"
if
((
$current
>
$oldest
))
;
then
oldest
=
"
${
current
}
"
fi
done
if
((
oldest
>=
0
))
;
then
echo
"
${
interval
}
.
${
oldest
}
"
return
0
else
return
1
fi
}
getnewest
()
{
local
-r
newest
=
"
${
interval
}
.0"
[[
-e
"
${
basedir
}
/
$newest
"
]]
&&
echo
"
$newest
"
}
getmtime
()
{
stat
-c
%Y
"
${
basedir
}
/
${
1
}
"
}
epochtodate
()
{
dconv
-i
%s
"
$1
"
}
getmtimeepoch
()
{
epochtodate
"
$(
getmtime
"
$1
"
)
"
}
testdifference
()
{
local
-r
date1
=
"
$1
"
date2
=
"
$2
"
difference
=
"
$3
"
dtest
"
$(
dadd
"
$date1
"
"
$difference
"
)
"
-ge
"
$date2
"
}
needsdaily
()
{
local
-r
newestdaily
=
"
$(
getnewest daily
)
"
if
[[
-z
"
$newestdaily
"
]]
;
then
return
0
fi
local
-r
oldesthourly
=
"
$(
getoldest hourly
)
"
if
testdifference
"
$(
getmtimeepoch
"
$newestdaily
"
)
"
"
$(
getmtimeepoch
"
$oldesthourly
"
)
"
1d
;
then
return
0
fi
return
1
}
dobackup
()
{
ionice
-c
2
-n
7
nice
rsnapshot
"
${
rsnapshotargs
[@]
}
"
-v
"
$1
"
}
(
if
!
flock
-x
-w
60 200
;
then
notify-send
-u
critical
-a
backup
"Backup failed"
"Failed to acquire lock"
exit
1
fi
if
needsdaily
;
then
dobackup daily
fi
dobackup hourly
)
200>
"
$lock
"
Write
Preview
Markdown
is supported
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