Skip to content
API Documentation
BastionGuard™
AppConsole Class Reference
Inheritance diagram for AppConsole:

Public Member Functions

bool start_application ()
bool delete_snapshot ()
bool delete_all_snapshots ()

Static Public Member Functions

static int main (string[] args)
static void check_if_admin ()

Public Attributes

int snapshot_list_start_index = 0

Private Member Functions

void list_snapshots (bool paginate, int page_size=20)
void list_devices (Gee.ArrayList< Device > device_list)
Gee.ArrayList< Device > list_all_devices ()
Gee.ArrayList< Device > list_grub_devices (bool print_to_console=true)
void print_grid (string[,] grid, bool[] right_align, bool has_header=true)
bool create_snapshot (bool ondemand)
bool restore_snapshot ()
void select_snapshot_device (bool prompt_if_empty)
Snapshot? select_snapshot ()
void select_snapshot_for_restore ()
void select_snapshot_for_deletion ()
void init_mounts ()
void map_devices ()
void select_grub_device ()
void confirm_restore ()
Device? read_stdin_device (Gee.ArrayList< Device > device_list, string device_default)
Device? read_stdin_device_mounts (Gee.ArrayList< Device > device_list, MountEntry mnt)
Device? get_device_from_index (Gee.ArrayList< Device > device_list, string index_string)
Snapshot read_stdin_snapshot ()
bool read_stdin_grub_install (bool reinstall_default)
bool read_stdin_restore_confirm ()

Static Private Member Functions

static void set_locale ()
static void parse_arguments (string[] args)
static string version_message ()
static string help_message ()

Detailed Description

Definition at line 50 of file AppConsole.vala.

Member Function Documentation

◆ check_if_admin()

void AppConsole.check_if_admin ( )
inlinestatic

Definition at line 105 of file AppConsole.vala.

105 {
106
107 if (!user_is_admin()) {
108 log_msg(_("Application needs admin access."));
109 log_msg(_("Please run the application as admin (using 'sudo' or 'su')"));
110 //App.exit_app(1);
111 exit(1);
112 }
113 }
void exit(int exit_code)
#define _(s)
void log_msg(string message, bool highlight=false)

References _, exit(), TeeJee.Logging.log_msg(), and TeeJee.System.user_is_admin().

Referenced by main().

◆ confirm_restore()

void AppConsole.confirm_restore ( )
inlineprivate

Definition at line 1103 of file AppConsole.vala.

1103 {
1104
1105 if (App.cmd_confirm == false){
1106
1107 string msg_devices = "";
1108 string msg_reboot = "";
1109 string msg_disclaimer = "";
1110
1112 false, out msg_devices, out msg_reboot,
1113 out msg_disclaimer);
1114
1115 int attempts = 0;
1116 while (App.cmd_confirm == false){
1117 attempts++;
1118 if (attempts > 3) { break; }
1119 stdout.printf(_("Continue with restore? (y/n): "));
1120 stdout.flush();
1122 }
1123
1124 if (App.cmd_confirm == false){
1125 log_error(_("Failed to get input from user in 3 attempts"));
1126 log_msg(_("Aborted."));
1127 App.exit_app(0);
1128 }
1129 }
1130 }
Main App
bool read_stdin_restore_confirm()
bool cmd_confirm
Definition Main.vala:149
void get_restore_messages(bool formatted, out string msg_devices, out string msg_reboot, out string msg_disclaimer)
Definition Main.vala:2400
void exit_app(int exit_code=0)
Definition Main.vala:4574
void log_error(string message, bool highlight=false, bool is_warning=false)

References _, App, Main.cmd_confirm, Main.exit_app(), Main.get_restore_messages(), TeeJee.Logging.log_error(), TeeJee.Logging.log_msg(), and read_stdin_restore_confirm().

Referenced by restore_snapshot().

◆ create_snapshot()

bool AppConsole.create_snapshot ( bool ondemand)
inlineprivate

Definition at line 612 of file AppConsole.vala.

612 {
614 return App.create_snapshot(ondemand, null);
615 }
void select_snapshot_device(bool prompt_if_empty)
bool create_snapshot(bool is_ondemand, Gtk.Window? parent_win)
Definition Main.vala:1082

References App, Main.create_snapshot(), and select_snapshot_device().

Referenced by start_application().

◆ delete_all_snapshots()

bool AppConsole.delete_all_snapshots ( )
inline

Definition at line 1368 of file AppConsole.vala.

1368 {
1369
1371
1372 //return App.repo.remove_all();
1373
1374 foreach(var snap in App.repo.snapshots){
1375 snap.remove(true);
1376 }
1377
1378 return true;
1379 }
SnapshotRepo repo
Definition Main.vala:70
Gee.ArrayList< Snapshot?> snapshots

References App, Main.repo, select_snapshot_device(), and SnapshotRepo.snapshots.

Referenced by start_application().

◆ delete_snapshot()

bool AppConsole.delete_snapshot ( )
inline

Definition at line 1355 of file AppConsole.vala.

1355 {
1356
1358
1360
1361 if (App.snapshot_to_delete != null){
1363 }
1364
1365 return true;
1366 }
void select_snapshot_for_deletion()
Snapshot snapshot_to_delete
Definition Main.vala:135
bool remove(bool wait)

References App, Snapshot.remove(), select_snapshot_device(), select_snapshot_for_deletion(), and Main.snapshot_to_delete.

Referenced by start_application().

◆ get_device_from_index()

Device? AppConsole.get_device_from_index ( Gee.ArrayList< Device > device_list,
string index_string )
inlineprivate

Definition at line 1213 of file AppConsole.vala.

1213 {
1214 int64 index;
1215 if (int64.try_parse(index_string, out index)){
1216 int i = -1;
1217 foreach(Device pi in device_list) {
1218 if (++i == index){
1219 return pi;
1220 }
1221 }
1222 }
1223
1224 return null;
1225 }

Referenced by read_stdin_device(), and read_stdin_device_mounts().

◆ help_message()

string AppConsole.help_message ( )
inlinestaticprivate

Definition at line 350 of file AppConsole.vala.

350 {
351
352 string msg = "\n%s v%s by Tony George (%s)\n".printf(
354
355 msg += "\n";
356 msg += "Syntax:\n";
357 msg += "\n";
358 msg += " bastionguard-backup --check\n";
359 msg += " bastionguard-backup --create [OPTIONS]\n";
360 msg += " bastionguard-backup --restore [OPTIONS]\n";
361 msg += " bastionguard-backup --delete-[all] [OPTIONS]\n";
362 msg += " bastionguard-backup --list-{snapshots|devices} [OPTIONS]\n";
363 msg += "\n";
364 msg += _("Options") + ":\n";
365 msg += "\n";
366 msg += _("List") + ":\n";
367 msg += " --list[-snapshots] " + _("List snapshots") + "\n";
368 msg += " --list-devices " + _("List devices") + "\n";
369 msg += "\n";
370 msg += _("Backup") + ":\n";
371 msg += " --check " + _("Create snapshot if scheduled") + "\n";
372 msg += " --create " + _("Create snapshot (even if not scheduled)") + "\n";
373 msg += " --comments <string> " + _("Set snapshot description") + "\n";
374 msg += " --tags {O,B,H,D,W,M} " + _("Add tags to snapshot (default: O)") + "\n";;
375 msg += "\n";
376 msg += _("Restore") + ":\n";
377 msg += " --restore " + _("Restore snapshot") + "\n";
378 //msg += " --clone " + _("Clone current system") + "\n"; // broken feature, not supported
379 msg += " --snapshot <name> " + _("Specify snapshot to restore") + "\n";
380 msg += " --target[-device] <device> " + _("Specify target device") + "\n";
381 msg += " --grub[-device] <device> " + _("Specify device for installing GRUB2 bootloader") + "\n";
382 msg += " --skip-grub " + _("Skip GRUB2 reinstall") + "\n";
383 msg += "\n";
384 msg += _("Delete") + ":\n";
385 msg += " --delete " + _("Delete snapshot") + "\n";
386 msg += " --delete-all " + _("Delete all snapshots") + "\n";
387 msg += "\n";
388 msg += _("Global") + ":\n";
389 msg += " --snapshot-device <device> " + _("Specify backup device (default: config)") + "\n";
390 msg += " --yes " + _("Answer YES to all confirmation prompts") + "\n";
391 msg += " --btrfs " + _("Switch to BTRFS mode (default: config)") + "\n";
392 msg += " --rsync " + _("Switch to RSYNC mode (default: config)") + "\n";
393 msg += " --debug " + _("Show additional debug messages") + "\n";
394 msg += " --verbose " + _("Show rsync output (default)") + "\n";
395 msg += " --quiet " + _("Hide rsync output") + "\n";
396 msg += " --scripted " + _("Run in non-interactive mode") + "\n";
397 msg += " --help " + _("Show all options") + "\n";
398 msg += " --version " + _("Print version number") + "\n";
399 msg += "\n";
400
401 msg += _("Examples") + ":\n";
402 msg += "\n";
403 msg += "bastionguard-backup --list\n";
404 msg += "bastionguard-backup --list --snapshot-device /dev/sda1\n";
405 msg += "bastionguard-backup --create --comments \"after update\" --tags D\n";
406 msg += "bastionguard-backup --restore \n";
407 msg += "bastionguard-backup --restore --snapshot '2014-10-12_16-29-08' --target /dev/sda1\n";
408 msg += "bastionguard-backup --delete --snapshot '2014-10-12_16-29-08'\n";
409 msg += "bastionguard-backup --delete-all \n";
410 msg += "\n";
411
412 msg += _("Notes") + ":\n";
413 msg += "\n";
414 msg += " 1) --create will always create a new snapshot\n";
415 msg += " 2) --check will create a snapshot only if a scheduled snapshot is due\n";
416 msg += " 3) Use --restore without other options to select options interactively\n";
417 msg += " 4) UUID can be specified instead of device name\n";
418 msg += " 5) Default values will be loaded from app config if options are not specified\n";
419 msg += "\n";
420 return msg;
421 }
const string AppName
const string AppVersion
const string AppAuthorEmail

References _, AppAuthorEmail, AppName, and AppVersion.

Referenced by main().

◆ init_mounts()

void AppConsole.init_mounts ( )
inlineprivate

Definition at line 810 of file AppConsole.vala.

810 {
811
812 log_debug("AppConsole: init_mounts()");
813
815
816 // remove mount points which will remain on root fs
817 for(int i = App.mount_list.size-1; i >= 0; i--){
818
819 var entry = App.mount_list[i];
820
821 if (entry.device == null){
822 App.mount_list.remove(entry);
823 }
824 }
825 }
Gee.ArrayList< MountEntry > mount_list
Definition Main.vala:67
void init_mount_list()
Definition Main.vala:2075
void log_debug(string message)

References App, Main.init_mount_list(), TeeJee.Logging.log_debug(), and Main.mount_list.

Referenced by restore_snapshot().

◆ list_all_devices()

Gee.ArrayList< Device > AppConsole.list_all_devices ( )
inlineprivate

Definition at line 492 of file AppConsole.vala.

492 {
493
494 //add devices
495 var device_list = new Gee.ArrayList<Device>();
496 foreach(var dev in Device.get_block_devices_using_lsblk()) {
497 if (dev.has_linux_filesystem()){
498 device_list.add(dev);
499 }
500 }
501
502 string[,] grid = new string[device_list.size+1,6];
503 bool[] right_align = { false, false, false, true, true, false};
504
505 int row = 0;
506 int col = -1;
507 grid[row, ++col] = _("Num");
508 grid[row, ++col] = "";
509 grid[row, ++col] = _("Device");
510 //grid[row, ++col] = _("UUID");
511 grid[row, ++col] = _("Size");
512 grid[row, ++col] = _("Type");
513 grid[row, ++col] = _("Label");
514 row++;
515
516 foreach(var pi in device_list) {
517 col = -1;
518 grid[row, ++col] = "%d".printf(row - 1);
519 grid[row, ++col] = ">";
520 grid[row, ++col] = "%s".printf(pi.device_name_with_parent);
521 //grid[row, ++col] = "%s".printf(pi.uuid);
522 grid[row, ++col] = "%s".printf((pi.size_bytes > 0) ? format_file_size(pi.size_bytes): "?? GB");
523 grid[row, ++col] = "%s".printf(pi.fstype);
524 grid[row, ++col] = "%s".printf(pi.label);
525 row++;
526 }
527
528 print_grid(grid, right_align);
529
530 return device_list;
531 }
void print_grid(string[,] grid, bool[] right_align, bool has_header=true)
string format_file_size(uint64 size, bool binary_units=false, string unit="", bool show_units=true, int decimals=1)

References _, TeeJee.FileSystem.format_file_size(), Device.get_block_devices_using_lsblk(), and print_grid().

Referenced by map_devices(), and start_application().

◆ list_devices()

void AppConsole.list_devices ( Gee.ArrayList< Device > device_list)
inlineprivate

Definition at line 461 of file AppConsole.vala.

461 {
462
463 string[,] grid = new string[device_list.size+1,6];
464 bool[] right_align = { false, false, false, true, true, false};
465
466 int row = 0;
467 int col = -1;
468 grid[row, ++col] = _("Num");
469 grid[row, ++col] = "";
470 grid[row, ++col] = _("Device");
471 //grid[row, ++col] = _("UUID");
472 grid[row, ++col] = _("Size");
473 grid[row, ++col] = _("Type");
474 grid[row, ++col] = _("Label");
475 row++;
476
477 foreach(var pi in device_list) {
478 col = -1;
479 grid[row, ++col] = "%d".printf(row - 1);
480 grid[row, ++col] = ">";
481 grid[row, ++col] = "%s".printf(pi.device_name_with_parent);
482 //grid[row, ++col] = "%s".printf(pi.uuid);
483 grid[row, ++col] = "%s".printf((pi.size_bytes > 0) ? "%s".printf(pi.size) : "?? GB");
484 grid[row, ++col] = "%s".printf(pi.fstype);
485 grid[row, ++col] = "%s".printf(pi.label);
486 row++;
487 }
488
489 print_grid(grid, right_align);
490 }

References _, and print_grid().

Referenced by select_snapshot_device().

◆ list_grub_devices()

Gee.ArrayList< Device > AppConsole.list_grub_devices ( bool print_to_console = true)
inlineprivate

Definition at line 533 of file AppConsole.vala.

533 {
534 //add devices
535 var grub_device_list = new Gee.ArrayList<Device>();
536 foreach(var dev in Device.get_block_devices_using_lsblk()) {
537 if (dev.type == "disk"){
538 grub_device_list.add(dev);
539 }
540 else if (dev.type == "part"){
541 if (dev.has_linux_filesystem()){
542 grub_device_list.add(dev);
543 }
544 }
545 // skip crypt/loop
546 }
547
548 /*Note: Lists are already sorted. No need to sort again */
549
550 string[,] grid = new string[grub_device_list.size+1,4];
551 bool[] right_align = { false, false, false, false };
552
553 int row = 0;
554 int col = -1;
555 grid[row, ++col] = _("Num");
556 grid[row, ++col] = "";
557 grid[row, ++col] = _("Device");
558 grid[row, ++col] = _("Description");
559 row++;
560
561 string desc = "";
562 foreach(Device pi in grub_device_list) {
563 col = -1;
564 grid[row, ++col] = "%d".printf(row - 1);
565 grid[row, ++col] = ">";
566 grid[row, ++col] = "%s".printf(pi.short_name_with_alias);
567
568 if (pi.type == "disk"){
569 desc = "%s".printf(((pi.vendor.length > 0)||(pi.model.length > 0)) ? (pi.vendor + " " + pi.model + " [MBR]") : "");
570 }
571 else{
572 desc = "%5s, ".printf(pi.fstype);
573 desc += "%10s".printf((pi.size_bytes > 0) ? "%s GB".printf(pi.size) : "?? GB");
574 desc += "%s".printf((pi.label.length > 0) ? ", " + pi.label : "");
575 }
576 grid[row, ++col] = "%s".printf(desc);
577 row++;
578 }
579
580 print_grid(grid, right_align);
581
582 return grub_device_list;
583 }
string type
Definition Device.vala:64
string model
Definition Device.vala:70
string short_name_with_alias
Definition Device.vala:1791
uint64 size_bytes
Definition Device.vala:77
string label
Definition Device.vala:51
string vendor
Definition Device.vala:69
string fstype
Definition Device.vala:65
string size
Definition Device.vala:126

References _, Device.get_block_devices_using_lsblk(), and print_grid().

Referenced by select_grub_device().

◆ list_snapshots()

void AppConsole.list_snapshots ( bool paginate,
int page_size = 20 )
inlineprivate

Definition at line 425 of file AppConsole.vala.

425 {
426 int count = 0;
427 for(int index = 0; index < App.repo.snapshots.size; index++){
428 if (!paginate || ((index >= snapshot_list_start_index) && (index < snapshot_list_start_index + page_size))){
429 count++;
430 }
431 }
432
433 string[,] grid = new string[count+1,5];
434 bool[] right_align = { false, false, false, false, false};
435
436 int row = 0;
437 int col = -1;
438 grid[row, ++col] = _("Num");
439 grid[row, ++col] = "";
440 grid[row, ++col] = _("Name");
441 grid[row, ++col] = _("Tags");
442 grid[row, ++col] = _("Description");
443 row++;
444
445 for(int index = 0; index < App.repo.snapshots.size; index++){
446 Snapshot bak = App.repo.snapshots[index];
447 if (!paginate || ((index >= snapshot_list_start_index) && (index < snapshot_list_start_index + page_size))){
448 col = -1;
449 grid[row, ++col] = "%d".printf(index);
450 grid[row, ++col] = ">";
451 grid[row, ++col] = "%s".printf(bak.name);
452 grid[row, ++col] = "%s".printf(bak.taglist_short);
453 grid[row, ++col] = "%s".printf(bak.description);
454 row++;
455 }
456 }
457
458 print_grid(grid, right_align);
459 }
int snapshot_list_start_index
string name
Definition Snapshot.vala:37
string description
Definition Snapshot.vala:42
string taglist_short

References _, App, Snapshot.description, Snapshot.name, print_grid(), Main.repo, snapshot_list_start_index, SnapshotRepo.snapshots, and Snapshot.taglist_short.

Referenced by read_stdin_snapshot(), select_snapshot(), and start_application().

◆ main()

int AppConsole.main ( string[] args)
inlinestatic

Definition at line 54 of file AppConsole.vala.

54 {
55
56 set_locale();
57
58 LOG_TIMESTAMP = false;
59
60 if (args.length > 1) {
61 switch (args[1].down()) {
62 case "--help":
63 case "-h":
64 stdout.printf (help_message ());
65 return 0;
66
67 case "--version":
68 stdout.printf (version_message ());
69 return 0;
70
71 }
72 }
73 else if (args.length == 1){
74 stdout.printf (help_message ());
75 return 0;
76 }
77
78 Main.setup_env();
79
80 LOG_ENABLE = false;
81 init_tmp();
82 LOG_ENABLE = true;
83
85
86 App = new Main(args, false);
87 parse_arguments(args);
89
90 var console = new AppConsole();
91 bool ok = console.start_application();
92 App.exit_app((ok) ? 0 : 1);
93
94 return (ok) ? 0 : 1;
95 }
static void check_if_admin()
static void set_locale()
static void parse_arguments(string[] args)
static string version_message()
static string help_message()
Main(string[] args, bool gui_mode)
Definition Main.vala:186
void initialize()
Definition Main.vala:337

References App, check_if_admin(), Main.exit_app(), help_message(), Main.initialize(), TeeJee.Logging.LOG_ENABLE, TeeJee.Logging.LOG_TIMESTAMP, Main.Main(), parse_arguments(), set_locale(), Main.setup_env(), and version_message().

◆ map_devices()

void AppConsole.map_devices ( )
inlineprivate

Definition at line 827 of file AppConsole.vala.

827 {
828
829 log_debug("AppConsole: map_devices()");
830
831 if (App.cmd_target_device.length > 0){
832
833 //check command line arguments
834 bool found = false;
835 foreach(Device pi in App.partitions) {
836
837 if (!pi.has_linux_filesystem()) { continue; }
838
839 if ((pi.device == App.cmd_target_device)||((pi.uuid == App.cmd_target_device))){
840 App.dst_root = pi;
841 found = true;
842 break;
843 }
844 else {
845 foreach(string symlink in pi.symlinks){
846 if (symlink == App.cmd_target_device){
847 App.dst_root = pi;
848 found = true;
849 break;
850 }
851 }
852 if (found){ break; }
853 }
854 }
855
856 //check if found
857 if (!found){
858 log_error(_("Could not find device") + ": '%s'".printf(App.cmd_target_device));
859 App.exit_app(1);
860 return;
861 }
862 }
863
864 for(int i = 0; i < App.mount_list.size; i++){
865
866 MountEntry mnt = App.mount_list[i];
867 Device dev = null;
868 string default_device = "";
869
870 log_debug("selecting: %s".printf(mnt.mount_point));
871
872 // no need to ask user to map remaining devices if restoring same system
873 if ((App.dst_root != null) && (App.sys_root != null)
874 && (App.dst_root.uuid == App.sys_root.uuid)){
875
876 break;
877 }
878
879 if (App.mirror_system){
880 default_device = (App.dst_root != null) ? App.dst_root.device : "";
881 }
882 else{
883 if (mnt.device != null){
884 default_device = mnt.device.device;
885 }
886 else{
887 default_device = (App.dst_root != null) ? App.dst_root.device : "";
888 }
889 }
890
891 if (App.cmd_scripted){
892 dev = Device.get_device_by_name(default_device);
893 if (dev == null){
894 log_error("Failed to get device by name %s".printf(default_device));
895 App.exit_app(1);
896 }
897 }
898
899 //prompt user for device
900 if (dev == null){
901 log_msg("");
902 log_msg(_("Select '%s' device (default = %s)").printf(
903 mnt.mount_point, default_device) + ":\n");
904 var device_list = list_all_devices();
905 log_msg("");
906
907 int attempts = 0;
908 while (dev == null){
909 attempts++;
910 if (attempts > 3) { break; }
911
912 stdout.printf("" +
913 _("[ENTER = Default (%s), r = Root device, a = Abort]").printf(default_device) + "\n\n");
914
915 stdout.printf(
916 _("Enter device name or number")
917 + ": ");
918
919 stdout.flush();
920 dev = read_stdin_device_mounts(device_list, mnt);
921 }
922 log_msg("");
923
924 if (dev == null){
925 log_error(_("Failed to get input from user in 3 attempts"));
926 log_msg(_("Aborted."));
927 App.exit_app(0);
928 }
929 }
930
931 if (dev != null){
932
933 log_debug("selected: %s".printf(dev.uuid));
934
935 mnt.device = dev;
936
937 log_msg(string.nfill(78, '*'));
938
939 if ((mnt.mount_point != "/")
940 && (App.dst_root != null)
941 && (dev.device == App.dst_root.device)){
942
943 log_msg(_("'%s' will be on root device").printf(mnt.mount_point), true);
944 }
945 else{
946 log_msg(_("'%s' will be on '%s'").printf(
948
949 //log_debug("UUID=%s".printf(dst_root.uuid));
950 }
951 log_msg(string.nfill(78, '*'));
952 }
953
954 }
955 }
Device? read_stdin_device_mounts(Gee.ArrayList< Device > device_list, MountEntry mnt)
Gee.ArrayList< Device > list_all_devices()
bool has_linux_filesystem()
Definition Device.vala:191
string uuid
Definition Device.vala:50
Gee.ArrayList< string > symlinks
Definition Device.vala:84
string device
Definition Device.vala:44
static ? Device get_device_by_name(string file_name)
Definition Device.vala:1086
Device sys_root
Definition Main.vala:75
Device? dst_root
Definition Main.vala:1948
Gee.ArrayList< Device > partitions
Definition Main.vala:59
string cmd_target_device
Definition Main.vala:146
bool mirror_system
Definition Main.vala:85
bool cmd_scripted
Definition Main.vala:151
string mount_point
Device device

References _, App, Main.cmd_scripted, Main.cmd_target_device, Device.device, MountEntry.device, Main.dst_root, Main.exit_app(), Device.get_device_by_name(), Device.has_linux_filesystem(), list_all_devices(), TeeJee.Logging.log_debug(), TeeJee.Logging.log_error(), TeeJee.Logging.log_msg(), Main.mirror_system, Main.mount_list, MountEntry.mount_point, Main.partitions, read_stdin_device_mounts(), Device.short_name_with_alias, Device.symlinks, Main.sys_root, and Device.uuid.

Referenced by restore_snapshot().

◆ parse_arguments()

void AppConsole.parse_arguments ( string[] args)
inlinestaticprivate

Definition at line 117 of file AppConsole.vala.

117 {
118
119 log_debug("AppConsole: parse_arguments()");
120
121 for (int k = 1; k < args.length; k++) // Oth arg is app path
122 {
123 switch (args[k].down()){
124 //case "--backup": // deprecated
125 case "--check":
126 LOG_TIMESTAMP = false;
127 LOG_DEBUG = false;
128 App.app_mode = "backup";
129 break;
130
131 case "--delete":
132 LOG_TIMESTAMP = false;
133 LOG_DEBUG = false;
134 App.app_mode = "delete";
135 break;
136
137 case "--delete-all":
138 LOG_TIMESTAMP = false;
139 LOG_DEBUG = false;
140 App.app_mode = "delete-all";
141 break;
142
143 case "--restore":
144 LOG_TIMESTAMP = false;
145 LOG_DEBUG = false;
146 App.mirror_system = false;
147 App.app_mode = "restore";
148 break;
149
150 case "--clone":
151 LOG_TIMESTAMP = false;
152 LOG_DEBUG = false;
153 App.mirror_system = true;
154 App.app_mode = "restore";
155 break;
156
157 //case "--backup-now": // deprecated
158 case "--create":
159 LOG_TIMESTAMP = false;
160 LOG_DEBUG = false;
161 App.app_mode = "ondemand";
162 break;
163
164 case "--comment":
165 case "--comments":
166 App.cmd_comments = args[++k];
167 break;
168
169 case "--skip-grub":
170 App.cmd_skip_grub = true;
171 break;
172
173 case "--verbose":
174 App.cmd_verbose = true;
175 break;
176
177 case "--quiet":
178 App.cmd_verbose = false;
179 break;
180
181 case "--scripted":
182 App.cmd_scripted = true;
183 App.cmd_confirm = true;
184 break;
185
186 case "--yes":
187 App.cmd_confirm = true;
188 break;
189
190 case "--grub":
191 case "--grub-device":
192 App.reinstall_grub2 = true;
193 App.cmd_grub_device = args[++k];
194 break;
195
196 case "--target":
197 case "--target-device":
198 App.cmd_target_device = args[++k];
199 break;
200
201 case "--backup-device":
202 case "--snapshot-device":
203 App.cmd_backup_device = args[++k];
204 break;
205
206 case "--snapshot":
207 case "--snapshot-name":
208 App.cmd_snapshot = args[++k];
209 break;
210
211 case "--tags":
212 App.cmd_tags = args[++k];
214 break;
215
216 case "--debug":
217 LOG_COMMANDS = true;
218 LOG_DEBUG = true;
219 break;
220
221 case "--list":
222 case "--list-snapshots":
223 App.app_mode = "list-snapshots";
224 LOG_TIMESTAMP = false;
225 LOG_DEBUG = false;
226 break;
227
228 case "--list-devices":
229 App.app_mode = "list-devices";
230 LOG_TIMESTAMP = false;
231 LOG_DEBUG = false;
232 break;
233
234 case "--btrfs":
235 App.btrfs_mode = true;
236 App.cmd_btrfs_mode = true;
237 break;
238
239 case "--rsync":
240 App.btrfs_mode = false;
241 App.cmd_btrfs_mode = false;
242 break;
243
244 case "--backup":
245 log_error("Option --backup has been replaced by option --check");
246 log_error("Run 'bastionguard-backup --help' to list all available options");
247 App.exit_app(1);
248 break;
249
250 case "--backup-now":
251 log_error("Option --backup-now has been replaced by option --create");
252 log_error("Run 'bastionguard-backup --help' to list all available options");
253 App.exit_app(1);
254 break;
255
256 default:
257 LOG_TIMESTAMP = false;
258 log_error("%s: %s".printf(
259 _("Invalid command line arguments"), args[k]), true);
260 log_error("Run 'bastionguard-backup --help' to list all available options");
261 App.app_mode = "abort";
262 App.exit_app(1);
263 break;
264 }
265 }
266
267 /* LOG_ENABLE = false; disables all console output
268 * LOG_TIMESTAMP = false; disables the timestamp prepended to every line in terminal output
269 * LOG_DEBUG = false; disables additional console messages
270 * LOG_COMMANDS = true; enables printing of all commands on terminal
271 * */
272
273 //if (app_mode == ""){
274 //Initialize GTK
275 // LOG_TIMESTAMP = true;
276 //}
277
278 //Gtk.init();
279 //X.init_threads();
280 }
void validate_cmd_tags()
Definition Main.vala:1861

References _, App, Main.exit_app(), TeeJee.Logging.LOG_COMMANDS, TeeJee.Logging.LOG_DEBUG, TeeJee.Logging.log_debug(), TeeJee.Logging.log_error(), TeeJee.Logging.LOG_TIMESTAMP, and Main.validate_cmd_tags().

Referenced by main().

◆ print_grid()

void AppConsole.print_grid ( string grid[,],
bool[] right_align,
bool has_header = true )
inlineprivate

Definition at line 585 of file AppConsole.vala.

585 {
586 int[] col_width = new int[grid.length[1]];
587
588 for(int col=0; col<grid.length[1]; col++){
589 for(int row=0; row<grid.length[0]; row++){
590 if (grid[row,col].length > col_width[col]){
591 col_width[col] = grid[row,col].length;
592 }
593 }
594 }
595
596 for(int row=0; row<grid.length[0]; row++){
597 for(int col=0; col<grid.length[1]; col++){
598 string fmt = "%" + (right_align[col] ? "+" : "-") + col_width[col].to_string() + "s ";
599 stdout.printf(fmt.printf(grid[row,col]));
600 }
601 stdout.printf("\n");
602
603 if (has_header && (row == 0)){
604 stdout.printf(string.nfill(78, '-'));
605 stdout.printf("\n");
606 }
607 }
608 }

Referenced by list_all_devices(), list_devices(), list_grub_devices(), and list_snapshots().

◆ read_stdin_device()

Device? AppConsole.read_stdin_device ( Gee.ArrayList< Device > device_list,
string device_default )
inlineprivate

Definition at line 1132 of file AppConsole.vala.

1132 {
1133
1134 var counter = new TimeoutCounter();
1135 counter.exit_on_timeout();
1136 string? line = stdin.read_line();
1137 counter.stop();
1138
1139 line = (line != null) ? line.strip() : "";
1140
1141 Device selected_device = null;
1142
1143 if (line.down() == "a"){
1144 log_msg(_("Aborted."));
1145 App.exit_app(0);
1146 }
1147 else if ((line == null)||(line.length == 0)||(line.down() == "c")||(line.down() == "d")){
1148 if (device_default.length > 0){
1149 selected_device = Device.get_device_by_name(device_default);
1150 }
1151 else{
1152 log_error("Invalid input");
1153 }
1154 }
1155 else if (line.contains("/")){
1156 selected_device = Device.get_device_by_name(line);
1157 if (selected_device == null){
1158 log_error("Invalid input");
1159 }
1160 }
1161 else{
1162 selected_device = get_device_from_index(device_list, line);
1163 if (selected_device == null){
1164 log_error("Invalid input");
1165 }
1166 }
1167
1168 return selected_device;
1169 }
Device? get_device_from_index(Gee.ArrayList< Device > device_list, string index_string)

References _, App, Main.exit_app(), Device.get_device_by_name(), get_device_from_index(), TeeJee.Logging.log_error(), and TeeJee.Logging.log_msg().

Referenced by select_grub_device(), and select_snapshot_device().

◆ read_stdin_device_mounts()

Device? AppConsole.read_stdin_device_mounts ( Gee.ArrayList< Device > device_list,
MountEntry mnt )
inlineprivate

Definition at line 1171 of file AppConsole.vala.

1171 {
1172 var counter = new TimeoutCounter();
1173 counter.exit_on_timeout();
1174 string? line = stdin.read_line();
1175 counter.stop();
1176
1177 line = (line != null) ? line.strip() : "";
1178
1179 Device selected_device = null;
1180
1181 if ((line == null)||(line.length == 0)||(line.down() == "c")||(line.down() == "d")){
1182 //set default
1183 if (App.mirror_system){
1184 return App.dst_root; //root device
1185 }
1186 else{
1187 return mnt.device; //keep current
1188 }
1189 }
1190 else if (line.down() == "a"){
1191 log_msg("Aborted.");
1192 App.exit_app(0);
1193 }
1194 else if ((line.down() == "n")||(line.down() == "r")){
1195 return App.dst_root; //root device
1196 }
1197 else if (line.contains("/")){
1198 selected_device = Device.get_device_by_name(line);
1199 if (selected_device == null){
1200 log_error("Invalid input");
1201 }
1202 }
1203 else{
1204 selected_device = get_device_from_index(device_list, line);
1205 if (selected_device == null){
1206 log_error("Invalid input");
1207 }
1208 }
1209
1210 return selected_device;
1211 }

References App, MountEntry.device, Main.dst_root, Main.exit_app(), Device.get_device_by_name(), get_device_from_index(), TeeJee.Logging.log_error(), TeeJee.Logging.log_msg(), and Main.mirror_system.

Referenced by map_devices().

◆ read_stdin_grub_install()

bool AppConsole.read_stdin_grub_install ( bool reinstall_default)
inlineprivate

Definition at line 1283 of file AppConsole.vala.

1283 {
1284 var counter = new TimeoutCounter();
1285 counter.exit_on_timeout();
1286 string? line = stdin.read_line();
1287 counter.stop();
1288
1289 line = (line != null) ? line.strip() : line;
1290
1291 if ((line == null)||(line.length == 0)){
1292 App.reinstall_grub2 = reinstall_default;
1293 App.cmd_skip_grub = !reinstall_default;
1294 return true;
1295 }
1296 else if (line.down() == "a"){
1297 log_msg("Aborted.");
1298 App.exit_app(0);
1299 return true;
1300 }
1301 else if (line.down() == "y"){
1302 App.cmd_skip_grub = false;
1303 App.reinstall_grub2 = true;
1304 return true;
1305 }
1306 else if (line.down() == "n"){
1307 App.cmd_skip_grub = true;
1308 App.reinstall_grub2 = false;
1309 return true;
1310 }
1311 else if ((line == null)||(line.length == 0)){
1312 log_error("Invalid input");
1313 return false;
1314 }
1315 else{
1316 log_error("Invalid input");
1317 return false;
1318 }
1319 }

References App, Main.exit_app(), TeeJee.Logging.log_error(), and TeeJee.Logging.log_msg().

Referenced by select_grub_device().

◆ read_stdin_restore_confirm()

bool AppConsole.read_stdin_restore_confirm ( )
inlineprivate

Definition at line 1321 of file AppConsole.vala.

1321 {
1322 var counter = new TimeoutCounter();
1323 counter.exit_on_timeout();
1324
1325 string? line = stdin.read_line();
1326 counter.stop();
1327
1328 line = (line != null) ? line.strip() : "";
1329
1330 if ((line.down() == "a")||(line.down() == "n")){
1331 log_msg("Aborted.");
1332 App.exit_app(0);
1333 return true;
1334 }
1335 else if ((line == null)||(line.length == 0)){
1336 log_error("Invalid input");
1337 return false;
1338 }
1339 else if (line.down() == "y"){
1340 App.cmd_confirm = true;
1341 return true;
1342 }
1343 else if ((line == null)||(line.length == 0)){
1344 log_error("Invalid input");
1345 return false;
1346 }
1347 else{
1348 log_error("Invalid input");
1349 return false;
1350 }
1351 }

References App, Main.exit_app(), TeeJee.Logging.log_error(), and TeeJee.Logging.log_msg().

Referenced by confirm_restore().

◆ read_stdin_snapshot()

Snapshot AppConsole.read_stdin_snapshot ( )
inlineprivate

Definition at line 1227 of file AppConsole.vala.

1227 {
1228 var counter = new TimeoutCounter();
1229 counter.exit_on_timeout();
1230 string? line = stdin.read_line();
1231 counter.stop();
1232
1233 line = (line != null) ? line.strip() : "";
1234
1235 Snapshot selected_snapshot = null;
1236
1237 if (line.down() == "a"){
1238 log_msg("Aborted.");
1239 App.exit_app(0);
1240 }
1241 else if (line.down() == "p"){
1245 }
1246 log_msg("");
1247 list_snapshots(true);
1248 log_msg("");
1249 }
1250 else if (line.down() == "n"){
1251 if ((snapshot_list_start_index + 10) < App.repo.snapshots.size){
1253 }
1254 log_msg("");
1255 list_snapshots(true);
1256 log_msg("");
1257 }
1258 else if (line.contains("_")||line.contains("-")){
1259 //TODO: read name
1260 log_error("Invalid input");
1261 }
1262 else if ((line == null)||(line.length == 0)){
1263 log_error("Invalid input");
1264 }
1265 else{
1266 int64 index;
1267 if (int64.try_parse(line, out index)){
1268 if (index < App.repo.snapshots.size){
1269 selected_snapshot = App.repo.snapshots[(int) index];
1270 }
1271 else{
1272 log_error("Invalid input");
1273 }
1274 }
1275 else{
1276 log_error("Invalid input");
1277 }
1278 }
1279
1280 return selected_snapshot;
1281 }
void list_snapshots(bool paginate, int page_size=20)

References App, Main.exit_app(), list_snapshots(), TeeJee.Logging.log_error(), TeeJee.Logging.log_msg(), Main.repo, snapshot_list_start_index, and SnapshotRepo.snapshots.

Referenced by select_snapshot().

◆ restore_snapshot()

bool AppConsole.restore_snapshot ( )
inlineprivate

Definition at line 619 of file AppConsole.vala.

619 {
620
622
624
625 if (!App.cmd_scripted) {
626 stdout.printf("\n\n");
627 log_msg(string.nfill(78, '*'));
628 stdout.printf(_("To restore with default options, press the ENTER key for all prompts!") + "\n");
629 log_msg(string.nfill(78, '*'));
630 stdout.printf(_("\nPress ENTER to continue..."));
631 stdout.flush();
632 stdin.read_line();
633 }
634
635 init_mounts();
636
637 if (!App.btrfs_mode){
638
639 map_devices();
640
642 }
643
645
646 bool ok = App.mount_target_devices();
647 if (!ok){
648 return false;
649 }
650
651 return App.restore_snapshot(null);
652 }
void init_mounts()
void confirm_restore()
void select_grub_device()
void select_snapshot_for_restore()
void map_devices()
bool btrfs_mode
Definition Main.vala:52
bool restore_snapshot(Gtk.Window? parent_win)
Definition Main.vala:2298
bool mount_target_devices(Gtk.Window? parent_win=null)
Definition Main.vala:3910

References _, App, Main.btrfs_mode, Main.cmd_scripted, confirm_restore(), init_mounts(), TeeJee.Logging.log_msg(), map_devices(), Main.mount_target_devices(), Main.restore_snapshot(), select_grub_device(), select_snapshot_device(), and select_snapshot_for_restore().

Referenced by start_application().

◆ select_grub_device()

void AppConsole.select_grub_device ( )
inlineprivate

Definition at line 957 of file AppConsole.vala.

957 {
958
959 string grub_device_default = App.grub_device;
960 bool grub_reinstall_default = App.reinstall_grub2;
961 App.reinstall_grub2 = false;
962 App.grub_device = "";
963
964 if (App.cmd_grub_device.length > 0){
965
966 log_debug("Grub device is specified as command argument");
967
968 //check command line arguments
969 bool found = false;
970 var device_list = list_grub_devices(false);
971
972 foreach(Device dev in device_list) {
973
974 if ((dev.device == App.cmd_grub_device)
975 ||((dev.uuid.length > 0) && (dev.uuid == App.cmd_grub_device))){
976
977 App.grub_device = dev.device;
978 found = true;
979 break;
980 }
981 else {
982 if (dev.type == "part"){
983 foreach(string symlink in dev.symlinks){
984 if (symlink == App.cmd_grub_device){
985 App.grub_device = dev.device;
986 found = true;
987 break;
988 }
989 }
990 if (found){ break; }
991 }
992 }
993 }
994
995 //check if found
996 if (!found){
997 log_error(_("Could not find device") + ": '%s'".printf(App.cmd_grub_device));
998 App.exit_app(1);
999 return;
1000 }
1001 }
1002
1003 if (App.mirror_system){
1004 App.reinstall_grub2 = true;
1005 }
1006 else {
1007 if ((App.cmd_skip_grub == false) && (App.reinstall_grub2 == false)){
1008 log_msg("");
1009
1010 if (App.cmd_scripted) {
1011 App.reinstall_grub2 = grub_reinstall_default;
1012 }
1013 else if (App.cmd_confirm){
1014 // suppose that it would be as user would typed 'y' in read_stdin_grub_install
1015 App.reinstall_grub2 = true;
1016 }
1017 else {
1018 int attempts = 0;
1019 while ((App.cmd_skip_grub == false) && (App.reinstall_grub2 == false)){
1020 attempts++;
1021 if (attempts > 3) { break; }
1022 stdout.printf(_("Re-install GRUB2 bootloader?") + (grub_reinstall_default ? " (recommended)" : "") + " (y/n): ");
1023 stdout.flush();
1024 read_stdin_grub_install(grub_reinstall_default);
1025 }
1026
1027 if ((App.cmd_skip_grub == false) && (App.reinstall_grub2 == false)){
1028 log_error(_("Failed to get input from user in 3 attempts"));
1029 log_msg(_("Aborted."));
1030 App.exit_app(0);
1031 }
1032 }
1033 }
1034 }
1035
1036 if ((App.reinstall_grub2) && (App.grub_device.length == 0)){
1037
1038 log_msg("");
1039 log_msg(_("Select GRUB device") + ":\n");
1040 var device_list = list_grub_devices();
1041 log_msg("");
1042
1043 Device dev = null;
1044
1045 if (App.cmd_scripted){
1046 dev = Device.get_device_by_name(grub_device_default);
1047 if (dev == null){
1048 log_error("Failed to get grub device by name %s".printf(grub_device_default));
1049 App.exit_app(1);
1050 }
1051 }
1052 else {
1053 int attempts = 0;
1054 while (App.grub_device.length == 0){
1055 attempts++;
1056 if (attempts > 3) { break; }
1057
1058 if (grub_device_default.length > 0){
1059 stdout.printf("" +
1060 _("[ENTER = Default (%s), a = Abort]").printf(grub_device_default) + "\n\n");
1061 }
1062
1063 stdout.printf(_("Enter device name or number (a=Abort)") + ": ");
1064 stdout.flush();
1065
1066 var list = new Gee.ArrayList<Device>();
1067 foreach(var pi in App.partitions){
1068 if (pi.has_linux_filesystem()){
1069 list.add(pi);
1070 }
1071 }
1072
1073 dev = read_stdin_device(device_list, grub_device_default);
1074 if (dev != null) { break; }
1075 }
1076
1077 if (dev == null){
1078
1079 log_error(_("Failed to get input from user in 3 attempts"));
1080 log_msg(_("Aborted."));
1081 App.exit_app(0);
1082 }
1083 }
1084
1085 if (dev != null) { App.grub_device = dev.device; }
1086
1087 log_msg("");
1088 }
1089
1090 if ((App.reinstall_grub2) && (App.grub_device.length > 0)){
1091
1092 log_msg(string.nfill(78, '*'));
1093 log_msg(_("GRUB Device") + ": %s".printf(App.grub_device));
1094 log_msg(string.nfill(78, '*'));
1095 }
1096 else{
1097 log_msg(string.nfill(78, '*'));
1098 log_msg(_("GRUB will NOT be reinstalled"));
1099 log_msg(string.nfill(78, '*'));
1100 }
1101 }
bool read_stdin_grub_install(bool reinstall_default)
Device? read_stdin_device(Gee.ArrayList< Device > device_list, string device_default)
Gee.ArrayList< Device > list_grub_devices(bool print_to_console=true)
string cmd_grub_device
Definition Main.vala:145
bool cmd_skip_grub
Definition Main.vala:144
bool reinstall_grub2
Definition Main.vala:138
string grub_device
Definition Main.vala:141

References _, App, Main.cmd_confirm, Main.cmd_grub_device, Main.cmd_scripted, Main.cmd_skip_grub, Device.device, Main.exit_app(), Device.get_device_by_name(), Main.grub_device, list_grub_devices(), TeeJee.Logging.log_debug(), TeeJee.Logging.log_error(), TeeJee.Logging.log_msg(), Main.mirror_system, Main.partitions, read_stdin_device(), read_stdin_grub_install(), Main.reinstall_grub2, Device.symlinks, Device.type, and Device.uuid.

Referenced by restore_snapshot().

◆ select_snapshot()

Snapshot? AppConsole.select_snapshot ( )
inlineprivate

Definition at line 727 of file AppConsole.vala.

727 {
728
729 Snapshot selected_snapshot = null;
730
731 log_debug("AppConsole: select_snapshot()");
732
733 if (App.mirror_system){
734 return null;
735 }
736
737 if (App.cmd_snapshot.length > 0){
738
739 //check command line arguments
740 bool found = false;
741 foreach(var bak in App.repo.snapshots) {
742 if (bak.name == App.cmd_snapshot){
743 return bak;
744 }
745 }
746
747 //check if found
748 if (!found){
749 log_error(_("Could not find snapshot") + ": '%s'".printf(App.cmd_snapshot));
750 return null;
751 }
752 }
753
754 //prompt user for snapshot
755 if (selected_snapshot == null){
756
757 if (!App.repo.has_snapshots()){
758 log_error(_("No snapshots found on device") + ": '%s'".printf(App.repo.device.device));
759 App.exit_app(0);
760 return null;
761 }
762
763 if (App.cmd_scripted){
764 log_error("No snapshots selected. Use --snapshot to specify snapshots");
765 App.exit_app(1);
766 return null;
767 }
768
769 log_msg("");
770 log_msg(_("Select snapshot") + ":\n");
771 list_snapshots(true);
772 log_msg("");
773
774 int attempts = 0;
775 while (selected_snapshot == null){
776 attempts++;
777 if (attempts > 3) { break; }
778 stdout.printf(_("Enter snapshot number (a=Abort, p=Previous, n=Next)") + ": ");
779 stdout.flush();
780 selected_snapshot = read_stdin_snapshot();
781 }
782 log_msg("");
783
784 if (selected_snapshot == null){
785 log_error(_("Failed to get input from user in 3 attempts"));
786 log_msg(_("Aborted."));
787 App.exit_app(0);
788 }
789 }
790
791 return selected_snapshot;
792 }
Snapshot read_stdin_snapshot()
string cmd_snapshot
Definition Main.vala:148

References _, App, Main.cmd_scripted, Main.cmd_snapshot, Device.device, SnapshotRepo.device, Main.exit_app(), SnapshotRepo.has_snapshots(), list_snapshots(), TeeJee.Logging.log_debug(), TeeJee.Logging.log_error(), TeeJee.Logging.log_msg(), Main.mirror_system, read_stdin_snapshot(), Main.repo, and SnapshotRepo.snapshots.

Referenced by select_snapshot_for_deletion(), and select_snapshot_for_restore().

◆ select_snapshot_device()

void AppConsole.select_snapshot_device ( bool prompt_if_empty)
inlineprivate

Definition at line 654 of file AppConsole.vala.

654 {
655
656 if (App.mirror_system){
657 return;
658 }
659
660 var list = new Gee.ArrayList<Device>();
661 foreach(var pi in App.partitions){
662 if (pi.has_linux_filesystem()){
663 list.add(pi);
664 }
665 }
666
667 if ((App.repo.device == null) || (prompt_if_empty && (App.repo.snapshots.size == 0))){
668 //prompt user for backup device
669 log_msg("");
670
671 if (App.cmd_scripted){
672
673 if (App.repo.device == null){
674 if (App.backup_uuid.length == 0){
675 log_debug("device is null");
676 string status_message = _("Snapshot device not selected");
677 log_msg(status_message);
678 }
679 else{
680 string status_message = _("Snapshot device not available");
681 string status_details = _("Device not found") + ": UUID='%s'".printf(App.backup_uuid);
682 log_msg(status_message);
683 log_msg(status_details);
684 }
685 }
686
687 App.exit_app(1);
688 }
689
690 log_msg(_("Select backup device") + ":\n");
691 list_devices(list);
692 log_msg("");
693
694 Device dev = null;
695 int attempts = 0;
696 while (dev == null){
697 attempts++;
698 if (attempts > 3) { break; }
699 stdout.printf("" +
700 _("Enter device name or number (a=Abort)") + ": ");
701 stdout.flush();
702
703 dev = read_stdin_device(list, "");
704
705 if (App.btrfs_mode && !App.check_device_for_backup(dev, true)){
706 log_error(_("Selected snapshot device is not a system disk"));
707 log_error(_("Select BTRFS system disk with root subvolume (@)"));
708 dev = null;
709 }
710 }
711
712 log_msg("");
713
714 if (dev == null){
715 log_error(_("Failed to get input from user in 3 attempts"));
716 log_msg(_("Aborted."));
717 App.exit_app(1);
718 }
719
720 App.repo = new SnapshotRepo.from_device(dev, null, App.btrfs_mode);
721 if (!App.repo.available()){
722 App.exit_app(1);
723 }
724 }
725 }
void list_devices(Gee.ArrayList< Device > device_list)
string backup_uuid
Definition Main.vala:49
bool check_device_for_backup(Device dev, bool unlock)
Definition Main.vala:4148

References _, App, SnapshotRepo.available(), Main.backup_uuid, Main.btrfs_mode, Main.check_device_for_backup(), Main.cmd_scripted, SnapshotRepo.device, Main.exit_app(), SnapshotRepo.from_device(), list_devices(), TeeJee.Logging.log_debug(), TeeJee.Logging.log_error(), TeeJee.Logging.log_msg(), Main.mirror_system, Main.partitions, read_stdin_device(), Main.repo, and SnapshotRepo.snapshots.

Referenced by create_snapshot(), delete_all_snapshots(), delete_snapshot(), and restore_snapshot().

◆ select_snapshot_for_deletion()

void AppConsole.select_snapshot_for_deletion ( )
inlineprivate

Definition at line 802 of file AppConsole.vala.

802 {
803 App.snapshot_to_delete = select_snapshot();
804 if (App.snapshot_to_delete == null){
805 log_error("Snapshot not selected");
806 App.exit_app(1);
807 }
808 }
Snapshot? select_snapshot()

References App, Main.exit_app(), TeeJee.Logging.log_error(), select_snapshot(), and Main.snapshot_to_delete.

Referenced by delete_snapshot().

◆ select_snapshot_for_restore()

void AppConsole.select_snapshot_for_restore ( )
inlineprivate

Definition at line 794 of file AppConsole.vala.

794 {
795 App.snapshot_to_restore = select_snapshot();
796 if (App.snapshot_to_restore == null){
797 log_error("Snapshot not selected");
798 App.exit_app(1);
799 }
800 }
Snapshot snapshot_to_restore
Definition Main.vala:136

References App, Main.exit_app(), TeeJee.Logging.log_error(), select_snapshot(), and Main.snapshot_to_restore.

Referenced by restore_snapshot().

◆ set_locale()

void AppConsole.set_locale ( )
inlinestaticprivate

Definition at line 97 of file AppConsole.vala.

97 {
98 log_debug("setting locale...");
99 Intl.setlocale(GLib.LocaleCategory.ALL, "");
100 Intl.bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR);
101 Intl.bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
102 Intl.textdomain(GETTEXT_PACKAGE);
103 }
const string GETTEXT_PACKAGE
const string LOCALE_DIR

References GETTEXT_PACKAGE, LOCALE_DIR, and TeeJee.Logging.log_debug().

Referenced by main().

◆ start_application()

bool AppConsole.start_application ( )
inline

Definition at line 282 of file AppConsole.vala.

282 {
283
284 log_debug("AppConsole: start_application()");
285
286 bool is_success = true;
287
288 if (App.live_system()){
289 switch(App.app_mode){
290 case "backup":
291 case "ondemand":
292 log_error(_("Snapshots cannot be created in Live CD mode"));
293 return false;
294 }
295 }
296
297 switch(App.app_mode){
298 case "backup":
299 is_success = create_snapshot(false);
300 return is_success;
301
302 case "restore":
303 is_success = restore_snapshot();
304 return is_success;
305
306 case "delete":
307 is_success = delete_snapshot();
308 return is_success;
309
310 case "delete-all":
311 is_success = delete_all_snapshots();
312 return is_success;
313
314 case "ondemand":
315 is_success = create_snapshot(true);
316 return is_success;
317
318 case "list-snapshots":
319 LOG_ENABLE = true;
320
322
323 if (App.repo.has_snapshots()){
324 list_snapshots(false);
325 log_msg("");
326 return true;
327 }
328 else{
329 log_msg(_("No snapshots found"));
330 return false;
331 }
332
333 case "list-devices":
334 LOG_ENABLE = true;
335 log_msg("\n" + _("Devices with Linux file systems") + ":\n");
337 log_msg("");
338 return true;
339
340 default:
341 return true;
342 }
343 }
bool delete_all_snapshots()
bool restore_snapshot()
bool delete_snapshot()
bool create_snapshot(bool ondemand)
string app_mode
Definition Main.vala:98
bool live_system()
Definition Main.vala:1058

References _, App, Main.app_mode, create_snapshot(), delete_all_snapshots(), delete_snapshot(), SnapshotRepo.has_snapshots(), list_all_devices(), list_snapshots(), Main.live_system(), TeeJee.Logging.log_debug(), TeeJee.Logging.LOG_ENABLE, TeeJee.Logging.log_error(), TeeJee.Logging.log_msg(), SnapshotRepo.print_status(), Main.repo, and restore_snapshot().

◆ version_message()

string AppConsole.version_message ( )
inlinestaticprivate

Definition at line 345 of file AppConsole.vala.

345 {
346 string msg = "%s %s\n".printf( AppName, AppVersion);
347 return msg;
348 }

References AppName, and AppVersion.

Referenced by main().

Member Data Documentation

◆ snapshot_list_start_index

int AppConsole.snapshot_list_start_index = 0

Definition at line 52 of file AppConsole.vala.

Referenced by list_snapshots(), and read_stdin_snapshot().


The documentation for this class was generated from the following file: