diff options
author | Sebastian Reichel <sre@ring0.de> | 2013-05-18 13:08:15 +0200 |
---|---|---|
committer | Sebastian Reichel <sre@ring0.de> | 2013-05-18 13:08:15 +0200 |
commit | f6bea9c01cea3e3b05f33f3b668aef2ebf1b6508 (patch) | |
tree | 13d5b7d9f9a9c4bc053309c34c5bca941371bf71 /src/backup | |
parent | ed125d14ad89e37361cb2fffcf26de5a447e020b (diff) | |
download | serial-barcode-scanner-f6bea9c01cea3e3b05f33f3b668aef2ebf1b6508.tar.bz2 |
add backup tool
Diffstat (limited to 'src/backup')
-rw-r--r-- | src/backup/Makefile | 9 | ||||
-rw-r--r-- | src/backup/main.vala | 42 |
2 files changed, 51 insertions, 0 deletions
diff --git a/src/backup/Makefile b/src/backup/Makefile new file mode 100644 index 0000000..5ef9d87 --- /dev/null +++ b/src/backup/Makefile @@ -0,0 +1,9 @@ +all: backup + +backup: main.vala ../mail/mailer-interface.vala ../config/config-interface.vala + valac -o $@ --pkg gio-2.0 $^ + +clean: + rm -f backup + +.PHONY: all clean diff --git a/src/backup/main.vala b/src/backup/main.vala new file mode 100644 index 0000000..00ff623 --- /dev/null +++ b/src/backup/main.vala @@ -0,0 +1,42 @@ +/* Copyright 2013, Sebastian Reichel <sre@ring0.de> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +public static int main(string[] args) { + try { + Mailer mailer = Bus.get_proxy_sync(BusType.SESSION, "io.mainframe.shopsystem.Mail", "/io/mainframe/shopsystem/mailer"); + Config cfg = Bus.get_proxy_sync(BusType.SESSION, "io.mainframe.shopsystem.Config", "/io/mainframe/shopsystem/config"); + string dbfile = cfg.get_string("DATABASE", "file"); + + string mailpath = mailer.create_mail(); + Mail mail = Bus.get_proxy_sync(BusType.SESSION, "io.mainframe.shopsystem.Mail", mailpath); + + uint8[] dbdata; + FileUtils.get_data(dbfile, out dbdata); + + var now = new DateTime.now_local().format("%Y-%m-%d %H:%M"); + + mail.from = {"KtT Shopsystem", "shop@kreativitaet-trifft-technik.de"}; + mail.add_recipient({"KtT Shopsystem Backups", "shop-backup@kreativitaet-trifft-technik.de"}, RecipientType.TO); + mail.subject = "Backup KtT-Shopsystem "+now; + mail.set_main_part("You can find a backup of 'shop.db' attached to this mail.", MessageType.PLAIN); + mail.add_attachment("shop.db", "application/x-sqlite3", dbdata); + + mailer.send_mail(mailpath); + } catch(Error e) { + stderr.printf("Error: %s\n", e.message); + } + + return 0; +} |