Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove renaming of older status files with _ suffix #1962

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 18 additions & 20 deletions VMBackup/main/Utils/HandlerUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ def __init__(self, log, error, short_name):

def _get_log_prefix(self):
return '[%s-%s]' % (self._context._name, self._context._version)


# It is possible in certain restore scenarios, where old setting files are present in the config folder
# When new VM is created with same extension, the seq# starts with 0 again.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably better to explain how older setting files are retained in a new VM? I guess you are referring to the case when OS disk is created from a restore point or a snaphost.

# We should not read older setting files because of relying on reading the highest sequence number.
# Instead, we need to get the seq# of the .settings file with the latest LAST modified file time
def _get_current_seq_no(self, config_folder):
seq_no = -1
cur_seq_no = -1
Expand Down Expand Up @@ -330,8 +334,8 @@ def try_parse_context(self, seqNo):
return None
else:
if(self.operation is not None and self.operation.lower() == "enable"):
# we should keep the current status file
self.backup_settings_status_file(self._context._seq_no)
# we should keep the current settings file
self.backup_settings_file(self._context._seq_no)
self._context._config = self._parse_config(ctxt)
except Exception as e:
errorMsg = "Unable to parse context, error: %s, stack trace: %s" % (str(e), traceback.format_exc())
Expand Down Expand Up @@ -660,10 +664,6 @@ def do_status_report(self, operation, status, status_code, message, taskId = Non
stat_rept_file = self.do_status_json(operation, status, sub_stat, status_code, message, None, taskId, commandStartTimeUTCTicks, None, None,total_size,failure_flag)
stat_rept_file = "[" + json.dumps(stat_rept_file, cls = ComplexEncoder) + "]"

# rename all other status files, or the WALA would report the wrong
# status file.
# because the wala choose the status file with the highest sequence
# number to report.
return stat_rept, stat_rept_file

def write_to_status_file(self, stat_rept_file):
Expand All @@ -687,25 +687,18 @@ def is_status_file_exists(self):
self.log("exception is getting status file" + traceback.format_exc())
return False

def backup_settings_status_file(self, _seq_no):
self.log("current seq no is " + _seq_no)
# Identify all settings files in the directory that are not of the current sequence number, and
# Rename them to not have the .settings suffix.
def backup_settings_file(self, _seq_no):
self.log("current seq no is " + _seq_no)
for subdir, dirs, files in os.walk(self._context._config_dir):
for file in files:
try:
if(file.endswith('.settings') and file != (_seq_no + ".settings")):
new_file_name = file.replace(".","_")
os.rename(join(self._context._config_dir,file), join(self._context._config_dir,new_file_name))
except Exception as e:
self.log("failed to rename the status file.")

for subdir, dirs, files in os.walk(self._context._status_dir):
for file in files:
try:
if(file.endswith('.status') and file != (_seq_no + ".status")):
new_file_name = file.replace(".","_")
os.rename(join(self._context._status_dir,file), join(self._context._status_dir, new_file_name))
except Exception as e:
self.log("failed to rename the status file.")
self.log("failed to rename the settings file.")

def do_exit(self, exit_code, operation,status,code,message):
try:
Expand All @@ -731,7 +724,12 @@ def is_prev_in_transition(self):
last_seq = curr_seq - 1
if last_seq >= 0:
self.log("previous status and path: " + str(last_seq) + " " + str(self._context._status_dir))
status_file_prev = os.path.join(self._context._status_dir, str(last_seq) + '_status')
status_file_prev = os.path.join(self._context._status_dir, str(last_seq) + '.status')

#Adding below for backward compatibility, where prev code version would replace older status files with _status
if not os.path.isfile(status_file_prev):
status_file_prev = os.path.join(self._context._status_dir, str(last_seq) + '_status')

if os.path.isfile(status_file_prev) and os.access(status_file_prev, os.R_OK):
searchfile = open(status_file_prev, "r")
for line in searchfile:
Expand Down