-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
1,012 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
eve4ceph-mdti.o | ||
eve4ceph-mdti | ||
*.deb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
PACKAGE=eve4ceph-mdti | ||
VERSION=0.0.1 | ||
DATE=$(shell LANG=en_us_8859_1; date '+%b %d, %Y') | ||
DESTDIR= | ||
PREFIX=/usr | ||
SBINDIR=${PREFIX}/sbin | ||
DOCDIR=${PREFIX}/share/doc/${PACKAGE} | ||
|
||
DEB=${PACKAGE}_${VERSION}_all.deb | ||
|
||
all: ${DEB} | ||
|
||
.PHONY: dinstall | ||
dinstall: deb | ||
dpkg -i ${DEB} | ||
|
||
.PHONY: install | ||
install: | ||
install -d ${DESTDIR}${SBINDIR} | ||
install -m 0755 ${PACKAGE} ${DESTDIR}${SBINDIR} | ||
|
||
.PHONY: deb ${DEB} | ||
deb ${DEB}: | ||
rm -rf debian | ||
mkdir debian | ||
|
||
cc ${PACKAGE}.c `pkg-config --cflags glib-2.0` -o ${PACKAGE} | ||
|
||
make DESTDIR=${CURDIR}/debian install | ||
install -d -m 0755 debian/DEBIAN | ||
sed -e s/@@VERSION@@/${VERSION}/ -e s/@@PACKAGE@@/${PACKAGE}/ <control.in >debian/DEBIAN/control | ||
install -D -m 0644 copyright debian/${DOCDIR}/copyright | ||
install -m 0644 changelog debian/${DOCDIR}/ | ||
gzip -n -9 debian/${DOCDIR}/changelog | ||
dpkg-deb --build debian | ||
mv debian.deb ${DEB} | ||
#lintian ${DEB} | ||
rm -rf debian | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf debian *.deb ${PACKAGE}-*.tar.gz dist ${PACKAGE}.o ${PACKAGE} | ||
find . -name '*~' -exec rm {} ';' | ||
|
||
.PHONY: distclean | ||
distclean: clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,50 @@ | ||
# eve4ceph-mdti | ||
Merge Diff file To Image for Ceph | ||
|
||
Ceph Documentation | ||
|
||
[rbd incremental backup](http://docs.ceph.com/docs/master/dev/rbd-diff/) | ||
|
||
[rdb – manage rados block device (rbd) images](http://docs.ceph.com/docs/master/man/8/rbd/) | ||
|
||
[Original idea ceph_apply_diff](https://gp2x.org/ceph/ceph_apply_diff-0.1.tar.gz) | ||
|
||
``` | ||
______ __ _ _ ________ | ||
/ ____/___ / /____ _________ _____(_)_______ | | / / ____/ | ||
/ __/ / __ \/ __/ _ \/ ___/ __ \/ ___/ / ___/ _ \ | | / / __/ | ||
/ /___/ / / / /_/ __/ / / /_/ / / / (__ ) __/ | |/ / /___ | ||
/_____/_/ /_/\__/\___/_/ / .___/_/ /_/____/\___/ |___/_____/ | ||
/_/ | ||
EnterpriseVE Merge Diff file To Image for Ceph (Made in Italy) | ||
Usage: | ||
eve4ceph-mdti <FULL_IMAGE_FILE> <DIFF_FILE> | ||
eve4ceph-mdti version | ||
Report bugs to <[email protected]>. | ||
``` | ||
|
||
# Introduction | ||
Ceph implements merge-diff to obtain single diff (rbd merge-diff diff1 diff2 diff_all). | ||
This software assemble diff file into file raw image (rbd export). | ||
|
||
[For Backup and Restore Ceph see eve4ceph-barc](https://github.com/EnterpriseVE/eve4ceph-barc) | ||
|
||
# Configuration and use | ||
Download package eve4ceph-mdti_?.?.?-?_all.deb, on your host and install: | ||
``` | ||
wget https://github.com/EnterpriseVE/eve4ceph-mdti/releases/latest | ||
dpkg -i eve4ceph-mdti_?.?.?-?_all.deb | ||
``` | ||
This tool need basically no configuration. | ||
|
||
## Execution | ||
``` | ||
$ rbd export pool-rbd/vm-111-disk-1@snap1 vm-111-disk-1.img | ||
$ rbd export-diff pool-rbd/vm-111-disk-1 --from-snap snap1 vm-111-disk-1-snap1.diff | ||
$ eve4ceph-mdti vm-111-disk-1.img vm-111-disk-1-snap1.diff | ||
``` | ||
The file vm-111-disk-1.img is now current, like if you had run rbd export pool-rbd/vm-111-disk-1. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
eve4ceph-mdti (0.0.1) | ||
|
||
* Initial implementation fanstatic code | ||
|
||
-- EnterpriseVE Support Team <[email protected]> 19 Apr 2017 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Package: @@PACKAGE@@ | ||
Section: utils | ||
Version: @@VERSION@@ | ||
Priority: optional | ||
Architecture: all | ||
Homepage: http://www.enterpriseve.com/ | ||
Maintainer: EnterpriseVE Support Team <[email protected]> | ||
Description: Merge Diff file To Image for Ceph | ||
This package contains the EnterpriseVE Merge Diff file To Image for Ceph. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Copyright (C) 2016 EnterpriseVE | ||
|
||
This software is written by EnterpriseVE <[email protected]> | ||
|
||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
|
||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,210 @@ | ||
/* | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <glib.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#define MAX_LEN 1023 | ||
|
||
void main(int argc, char **argv) { | ||
|
||
FILE *fdiff; | ||
FILE *fimg; | ||
|
||
if (argc == 2 && strcmp(argv[1], "version") == 0) { | ||
//&& argv[1] == 'version' | ||
// printf(argv[1]); | ||
printf("0.0.1\n"); | ||
exit(0); | ||
} | ||
|
||
if (argc < 3) { | ||
printf(" ______ __ _ _ " | ||
"________\n"); | ||
printf(" / ____/___ / /____ _________ _____(_)_______ | | / / " | ||
"____/\n"); | ||
printf(" / __/ / __ \\/ __/ _ \\/ ___/ __ \\/ ___/ / ___/ _ \\ | | / / " | ||
"__/\n"); | ||
printf( | ||
" / /___/ / / / /_/ __/ / / /_/ / / / (__ ) __/ | |/ / /___\n"); | ||
printf("/_____/_/ /_/\\__/\\___/_/ / .___/_/ /_/____/\\___/ " | ||
"|___/_____/\n"); | ||
printf(" /_/\n\n"); | ||
|
||
printf("EnterpriseVE Merge Diff file To Image for Ceph (Made in " | ||
"Italy)\n\n"); | ||
|
||
printf("Usage:\n"); | ||
printf(" eve4ceph-mdti version\n"); | ||
printf(" eve4ceph-mdti <FULL_IMAGE_FILE> <DIFF_FILE>\n\n"); | ||
printf("Report bugs to <[email protected]>.\n"); | ||
exit(0); | ||
} | ||
|
||
// open image | ||
char *img = argv[1]; | ||
fimg = fopen(img, "r+"); | ||
if (fimg == NULL) { | ||
printf("Error opening image file %s\n", img); | ||
exit(1); | ||
} | ||
|
||
// opem diff file | ||
char *diff = argv[2]; | ||
fdiff = fopen(diff, "r"); | ||
if (fdiff == NULL) { | ||
printf("Error opening diff file %s\n", diff); | ||
exit(1); | ||
} | ||
|
||
// check header diff file | ||
char header[255]; | ||
if (fread(header, 1, 12, fdiff) != 12) { | ||
printf("Error reading diff header\n"); | ||
exit(1); | ||
} | ||
|
||
if (strncmp(header, "rbd diff v1", 11)) { | ||
printf("Unrecognised diff format\n"); | ||
exit(1); | ||
} | ||
|
||
int debug = 0; | ||
|
||
// reading metadata | ||
guint8 tag; | ||
int reading_metadata = 1; | ||
|
||
printf("Reading metadata\n"); | ||
while (reading_metadata) { | ||
if (fread(&tag, 1, 1, fdiff) != 1) { | ||
printf("Error reading metadata\n"); | ||
exit(1); | ||
} | ||
|
||
guint32 name_len; | ||
// int rlen; | ||
char name[MAX_LEN + 1]; | ||
guint64 image_size; | ||
|
||
switch (tag) { | ||
case 'f': // from snap | ||
case 't': // to snaps | ||
fread(&name_len, 1, sizeof(guint32), fdiff); | ||
int rlen = name_len > MAX_LEN ? MAX_LEN : name_len; | ||
fread(name, 1, rlen, fdiff); | ||
name[rlen] = 0; | ||
printf("%s snap: %s\n", (tag == 'f' ? "From" : "To"), name); | ||
if (name_len > MAX_LEN) { | ||
fseek(fdiff, name_len - MAX_LEN, SEEK_CUR); | ||
} | ||
break; | ||
|
||
case 's': // size | ||
fread(&image_size, 1, sizeof(guint64), fdiff); | ||
printf("Image size: %lu (%luGB)\n", image_size, | ||
image_size / (1024 * 1024 * 1024)); | ||
break; | ||
|
||
default: | ||
reading_metadata = 0; | ||
printf("End of metadata\n"); | ||
fseek(fdiff, -1, SEEK_CUR); | ||
break; | ||
} | ||
} | ||
|
||
char *rbuf = (char *)malloc(4096); | ||
char *zbuf = (char *)malloc(4096); | ||
memset((void *)zbuf, 0, 4096); | ||
|
||
int total_length = 0; | ||
|
||
// reading data | ||
int reading_data = 1; | ||
while (reading_data) { | ||
if (fread(&tag, 1, 1, fdiff) != 1) { | ||
printf("Error reading data\n"); | ||
exit(1); | ||
} | ||
|
||
guint64 offset; | ||
guint64 length; | ||
|
||
switch (tag) { | ||
case 'w': // Update data | ||
case 'z': // Zero data | ||
fread(&offset, 1, sizeof(guint64), fdiff); // offset | ||
fread(&length, 1, sizeof(guint64), fdiff); // length | ||
|
||
total_length += length; | ||
|
||
if (debug) { | ||
printf("Data at offset %lu of length %lu\n", offset, length); | ||
} | ||
|
||
int written = 0; | ||
while (written < length) { | ||
int l = (length - written > 4096) ? 4096 : length - written; | ||
|
||
if (tag == 'w') { | ||
if (fread(rbuf, 1, l, fdiff) != l) { | ||
printf("error reading diff file\n"); | ||
exit(0); | ||
} | ||
} | ||
|
||
if (fseek(fimg, offset + written, SEEK_SET)) { | ||
printf("error seeking in image file\n"); | ||
exit(0); | ||
} | ||
|
||
if (debug) { | ||
printf("writing %d bytes to image\n", l); | ||
} | ||
|
||
int n = 0; | ||
if (tag == 'w') { | ||
n = fwrite(rbuf, 1, l, fimg); | ||
} else if (tag == 'z') { | ||
n = fwrite(zbuf, 1, l, fimg); | ||
} | ||
|
||
written += n; | ||
if (n == 0) { | ||
printf("Error writing to image\n"); | ||
exit(0); | ||
} | ||
} | ||
break; | ||
|
||
case 'e': // End data | ||
reading_data = 0; | ||
printf("End of data\n"); | ||
printf("Writing %d bytes to image\n", total_length); | ||
break; | ||
|
||
default: | ||
reading_data = 0; | ||
printf("Unknown data encountered %d\n", tag); | ||
break; | ||
} | ||
} | ||
|
||
fclose(fimg); | ||
fclose(fdiff); | ||
} |