-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathedit_supported_files.pl
161 lines (137 loc) · 6.32 KB
/
edit_supported_files.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env perl
#*****************************************************************************************************
# This script is used to edit the supported files like Backup/Restore set files for both normal and scheduled
#
# Created By: Sabin Cheruvattil @ IDrive Inc
#****************************************************************************************************/
use strict;
use warnings;
use lib map{if(__FILE__ =~ /\//) { substr(__FILE__, 0, rindex(__FILE__, '/'))."/$_";} else { "./$_"; }} qw(Idrivelib/lib);
use Helpers;
use Strings;
use Configuration;
use File::Basename;
Helpers::initiateMigrate();
init();
#*****************************************************************************************************
# Subroutine : init
# Objective : This function is entry point for the script
# Added By : Sabin Cheruvattil
# Modified By : Anil Kumar [04/05/2018], Yogesh Kumar
#****************************************************************************************************/
sub init {
system('clear');
Helpers::loadAppPath();
Helpers::loadServicePath() or Helpers::retreat('invalid_service_directory');
Helpers::loadUsername() or Helpers::retreat('login_&_try_again');
my $errorKey = Helpers::loadUserConfiguration();
Helpers::retreat($Configuration::errorDetails{$errorKey}) if($errorKey != 1);
Helpers::isLoggedin() or Helpers::retreat('login_&_try_again');
Helpers::displayHeader();
my ($continueMenu, $menuUserChoice, $editFilePath, $maxMenuChoice) = ('y', 0, '', 0);
my (%menuToPathMap, $fileType);
while($continueMenu eq 'y') {
$maxMenuChoice = displayMenu(\%menuToPathMap);
Helpers::display(["\n", '__note_please_press_ctrlc_exit']);
$menuUserChoice = Helpers::getUserMenuChoice($maxMenuChoice);
$menuUserChoice += 0;
my $propSettings = Helpers::getPropSettings('master');
if ($menuToPathMap{$menuUserChoice} =~ '_exclude') {
if ($menuToPathMap{$menuUserChoice} eq 'partial_exclude') {
if (exists $propSettings->{'set'} and exists $propSettings->{'set'}{'lst_partexclude'} and
$propSettings->{'set'}{'lst_partexclude'}{'islocked'}) {
Helpers::display(["\n", 'admin_has_locked_settings', "\n"]);
next;
}
}
$editFilePath = Helpers::getUserFilePath($Configuration::excludeFilesSchema{$menuToPathMap{$menuUserChoice}}{'file'});
$fileType = $Configuration::excludeFilesSchema{$menuToPathMap{$menuUserChoice}}{'title'};
}
else {
if (($menuToPathMap{$menuUserChoice} eq 'backup') and exists $propSettings->{'bkpset_linux'} and exists $propSettings->{'bkpset_linux'}{'Default BackupSet'} and $propSettings->{'bkpset_linux'}{'Default BackupSet'}{'islocked'}) {
Helpers::display(["\n", 'admin_has_locked_settings', "\n"]);
next;
}
elsif (($menuToPathMap{$menuUserChoice} eq 'localbackup') and exists $propSettings->{'bkpset_linux'} and exists $propSettings->{'bkpset_linux'}{'LocalBackupSet'} and $propSettings->{'bkpset_linux'}{'LocalBackupSet'}{'islocked'}) {
Helpers::display(["\n", 'admin_has_locked_settings', "\n"]);
next;
}
my $editFilePathPid = Helpers::getJobsPath($menuToPathMap{$menuUserChoice}).$Configuration::pidFile;
if(-e $editFilePathPid){
open(my $fh, ">>", $editFilePathPid) or return 0;
unless (flock($fh, 2|4)) {
Helpers::display(["\n",$menuToPathMap{$menuUserChoice}.'_in_progress_try_again']);
Helpers::display(["\n",'do_you_want_to_edit_any_other_files_yn']);
$continueMenu = Helpers::getAndValidate(['enter_your_choice'], "YN_choice", 1);
($continueMenu eq 'y')? next:exit;
}else{
flock($fh, 8);
}
}
$editFilePath = Helpers::getJobsPath($menuToPathMap{$menuUserChoice}, 'file');
$fileType = $menuToPathMap{$menuUserChoice};
}
(-f $editFilePath)? Helpers::openEditor('edit', $editFilePath, $fileType) : Helpers::display(['unable_to_open', '. ', 'invalid_file_path', ' ', '["', $editFilePath, '"]']);
if ($menuToPathMap{$menuUserChoice} =~ '_exclude') {
Helpers::updateExcludeFileset($editFilePath, $menuToPathMap{$menuUserChoice});
calculateJobsetSize('backup');
calculateJobsetSize('localbackup');
}
else {
Helpers::updateJobsFileset($editFilePath, $menuToPathMap{$menuUserChoice});
calculateJobsetSize($menuToPathMap{$menuUserChoice}) if($menuToPathMap{$menuUserChoice} eq 'backup' || $menuToPathMap{$menuUserChoice} eq 'localbackup');
}
Helpers::display(['do_you_want_to_edit_any_other_files_yn']);
$continueMenu = Helpers::getAndValidate(['enter_your_choice'], "YN_choice", 1);
}
}
#*****************************************************************************************************
# Subroutine : calculateJobsetSize
# Objective : Helps calculate backupset size
# Added By : Sabin Cheruvattil
#****************************************************************************************************/
sub calculateJobsetSize {
my $backupsizelock = Helpers::getBackupsetSizeLockFile($_[0]);
return 0 if(Helpers::isFileLocked($backupsizelock));
my $calcforkpid = fork();
if($calcforkpid == 0) {
$0 = 'IDrive:esf:szcal';
Helpers::calculateBackupsetDirectorySize($_[0]);
while(1) {
if (Helpers::isFileLocked($backupsizelock)) {
sleep(1);
}
else {
last;
}
}
Helpers::loadNotifications() and Helpers::setNotification(sprintf("get_%sset_content", $_[0])) and Helpers::saveNotifications();
exit(0);
}
}
#*****************************************************************************************************
# Subroutine : displayMenu
# Objective : Helps to display the menu
# Added By : Sabin Cheruvattil
# Modified By : Yogesh Kumar
#****************************************************************************************************/
sub displayMenu {
my ($opIndex, $pathIndex) = (1, 1);
my @fileMenuOptions;
tie (our %editFileOptions, 'Tie::IxHash',
'backup' => ['backup'],
'express_backup' => ['localbackup'],
'exclude' => ['full_exclude', 'partial_exclude', 'regex_exclude'],
'restore' => ['restore'],
);
Helpers::display(['menu_options_title', ':', "\n"]);
foreach my $mainOperation (keys %editFileOptions) {
Helpers::display([$mainOperation . '_title', ':']);
@fileMenuOptions = @{$editFileOptions{$mainOperation}};
foreach (@fileMenuOptions) {
Helpers::display(["\t" . $opIndex++ . ') ', "edit_$_\_file"]);
}
%{$_[0]} = (%{$_[0]}, map{$pathIndex++ => $_} @fileMenuOptions);
}
return $opIndex - 1;
}