FAQ
| This is a
LIVE
service |
Changelog
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
backup-scheduler
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Yusuf Hamied Department of Chemistry
COs
backup-scheduler
Commits
04e7b9a0
Commit
04e7b9a0
authored
7 years ago
by
Dr Catherine Pitt
Browse files
Options
Downloads
Patches
Plain Diff
Add script for migrating from rsnapshot style backups
parent
8f7a5957
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
ROOT/DEBIAN/control
+1
-1
1 addition, 1 deletion
ROOT/DEBIAN/control
ROOT/usr/lib/chem-zfs-backup-server/migrate-machine.sh
+108
-0
108 additions, 0 deletions
ROOT/usr/lib/chem-zfs-backup-server/migrate-machine.sh
with
109 additions
and
1 deletion
ROOT/DEBIAN/control
+
1
−
1
View file @
04e7b9a0
...
...
@@ -3,7 +3,7 @@ Priority: optional
Section: otherosfs
Maintainer: Frank Lee <rl201@cam.ac.uk>
Architecture: all
Version: 0.9-ch4
5
Version: 0.9-ch4
6
Depends: zfs-dkms, postgresql, liblockfile-simple-perl, libdbi-perl, libjson-perl, libzfs-perl-chem, libnet-openssh-perl, libdbd-pg-perl, mbuffer, rsync, nfs-kernel-server, pv
Description: a backup system using ZFS
Ported (well, mostly) from FreeBSD to a Sane OS.
This diff is collapsed.
Click to expand it.
ROOT/usr/lib/chem-zfs-backup-server/migrate-machine.sh
0 → 100755
+
108
−
0
View file @
04e7b9a0
#!/bin/bash
set
-e
set
-x
# create a new ZFS filesystem for the target
# look for all the rnspashots and sort by date
# from oldest, rsync it into the ZFS and then snapshot it with a name that matches its old date and tag it matching old name
if
[
-z
"
$1
"
]
then
echo
usage:
$0
fqdn
[
zpool]
exit
1
fi
which bc
>
/dev/null
||
(
echo
"Could not find bc command"
;
exit
1
)
function
ensurezpool
()
{
if
[
-n
"
$1
"
]
then
echo
$1
else
(
for
z
in
$(
zpool list
-H
-oname
)
do
zfs list
-H
-p
-oavail
,name
$z
done
)
|
sort
-nr
|
head
-1
|
cut
-f2
fi
}
function
ensurelv
()
{
LV
=
$(
lvs
-o
lv_path
--noheadings
-S
"lv_name=
$1
"
|
head
-1
|sed
's/ *//'
)
if
[
-z
"
$LV
"
]
then
echo
Cannot find LV
for
$SN
exit
2
fi
echo
$LV
}
function
mount_lv
()
{
mkdir
-p
/rsnapshots/
$2
mount
$LV
/rsnapshots/
$2
2>/dev/null
||
echo
already mounted
}
function
umount_lv
()
{
HN
=
$1
make
-f
/usr/local/rsnapshots/Makefile
${
HN
}
-umount
||
umount
-l
/rsnapshots/
$HN
}
function
ensure_zfs
()
{
ZPOOL
=
$1
HN
=
$2
QUOTA
=
$3
ZFS
=
$(
zfs list
-H
-d1
-oname
|
grep
$HN
)
if
[
-n
"
$ZFS
"
]
then
>
&2
echo
ZFS
$ZFS
already exists, using that
else
ZFS
=
$ZPOOL
/
$HN
zfs create
$ZFS
zfs create
$ZFS
/zfs-rsnap
fi
zfs
set
quota
=
$QUOTA
$ZFS
echo
$ZFS
}
function
get_quota
()
{
SIZE
=
$(
lvs
--no-headings
-osize
--units
=
b
$1
|
sed
's/ *//'
|
sed
's/B$//'
)
printf
"%.0f
\n
"
$(
echo
$SIZE
*
1.1 | bc
)
}
function
sync_backups
()
{
HN
=
$1
ZFS
=
$2
TARGETDIR
=
$ZFS
/zfs-rsnap
SOURCEDIR
=
/rsnapshots/
$HN
for
incremental
in
$(
ls
-tr
$SOURCEDIR
|
grep
-v
'lost+found'
)
do
TIME
=
$(
stat
-c
"%Y"
$SOURCEDIR
/
$incremental
)
if
!
zfs list
-t
snapshot
${
TARGETDIR
}
@
${
TIME
}
>
/dev/null
then
rsync
-aq
--delete
$SOURCEDIR
/
$incremental
/ /
$TARGETDIR
TAG
=
$(
echo
$incremental
|
sed
's/\.[0-9]//'
)
zfs snapshot
${
TARGETDIR
}
@
${
TIME
}
zfs hold
$TAG
${
TARGETDIR
}
@
${
TIME
}
else
echo
Already synced
${
TARGETDIR
}
@
${
TIME
}
fi
done
}
ZPOOL
=
$(
ensurezpool
$2
)
HN
=
$1
SN
=
$(
echo
$HN
|
sed
's/\..*$//'
)
LV
=
$(
ensurelv
$SN
)
QUOTA
=
$(
get_quota
$LV
)
mount_lv
$LV
$HN
ZFS
=
$(
ensure_zfs
$ZPOOL
$HN
$QUOTA
)
sync_backups
$HN
$ZFS
echo
$HN
$SN
$ZPOOL
$LV
$ZFS
$QUOTA
umount_lv
$HN
if
[
-f
/etc/rsnapshot.conf.d/
$HN
]
then
/usr/lib/chem-zfs-backup-server/new-backup-rsnapshot
$HN
mv
/etc/rsnapshot.conf.d/
$HN
/etc/rsnapshot.conf.d/attic
fi
rmdir
/rsnapshots/
${
HN
}
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