Skip to content

Commit

Permalink
Add progress bar when scanning a backup.
Browse files Browse the repository at this point in the history
  • Loading branch information
prwater committed May 9, 2019
1 parent 94b81d0 commit 283e732
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
12 changes: 7 additions & 5 deletions backuppc_clone/helper/BackupInfoScanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def __init__(self, io):
"""

# ------------------------------------------------------------------------------------------------------------------
def __get_backup_info(self, backup_dir, param_name):
@staticmethod
def get_backup_info(backup_dir, param_name):
"""
Extracts info about a backup from file backupInfo.
Expand All @@ -39,6 +40,7 @@ def __get_backup_info(self, backup_dir, param_name):
:rtype: str|None
"""
ret = None

path = os.path.join(backup_dir, 'backupInfo')
if os.path.isfile(path):
with open(path) as file:
Expand Down Expand Up @@ -72,10 +74,10 @@ def __scan_for_backups(self):
backup_dir = os.path.join(host_dir, backup.name)
backups.append({'bob_host': host.name,
'bob_number': int(backup.name),
'bob_end_time': self.__get_backup_info(backup_dir, 'endTime'),
'bob_version': self.__get_backup_info(backup_dir, 'version'),
'bob_level': self.__get_backup_info(backup_dir, 'level'),
'bob_type': self.__get_backup_info(backup_dir, 'type')})
'bob_end_time': self.get_backup_info(backup_dir, 'endTime'),
'bob_version': self.get_backup_info(backup_dir, 'version'),
'bob_level': self.get_backup_info(backup_dir, 'level'),
'bob_type': self.get_backup_info(backup_dir, 'type')})

return backups

Expand Down
23 changes: 23 additions & 0 deletions backuppc_clone/helper/BackupScanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import shutil

from backuppc_clone.Config import Config
from backuppc_clone.ProgressBar import ProgressBar
from backuppc_clone.helper.BackupInfoScanner import BackupInfoScanner


class BackupScanner:
Expand Down Expand Up @@ -49,6 +51,13 @@ def __init__(self, io):
:type: int
"""

self.progress = None
"""
The progress counter.
:type: backuppc_clone.ProgressBar.ProgressBar
"""

# ------------------------------------------------------------------------------------------------------------------
@property
def dir_count(self):
Expand Down Expand Up @@ -90,6 +99,9 @@ def __scan_directory_helper(self, parent_dir, dir_name, csv_writer):
self.__entry_seq += 1
csv_writer.writerow((self.__entry_seq, entry.inode(), dir_name, entry.name))

if entry.name not in ['attrib', 'backupInfo', 'backuppc-clone.csv']:
self.progress.advance()

elif entry.is_dir():
sub_dir_names.append(entry.name)

Expand All @@ -114,10 +126,15 @@ def scan_directory(self, host, backup_no, csv_filename):

backup_dir = Config.instance.backup_dir_original(host, backup_no)

file_count = int(BackupInfoScanner.get_backup_info(backup_dir, 'nFiles'))
self.progress = ProgressBar(self.__io.output, file_count)

with open(csv_filename, 'wt') as csv_file:
csv_writer = csv.writer(csv_file)
self.__io.writeln(' Scanning <fso>{}</fso>'.format(backup_dir))
self.__io.writeln('')
self.__scan_directory_helper(backup_dir, '', csv_writer)
self.progress.finish()

# ------------------------------------------------------------------------------------------------------------------
def pre_scan_directory(self, host, backup_no):
Expand All @@ -136,12 +153,18 @@ def pre_scan_directory(self, host, backup_no):
csv_filename1 = os.path.join(Config.instance.tmp_dir_clone, '.backup-{}-{}.csv'.format(host, backup_no))
csv_filename2 = os.path.join(backup_dir, 'backuppc-clone.csv')

file_count = int(BackupInfoScanner.get_backup_info(backup_dir, 'nFiles'))
self.progress = ProgressBar(self.__io.output, file_count)

with open(csv_filename1, 'wt') as csv_file:
csv_writer = csv.writer(csv_file)
self.__io.writeln(' Scanning <fso>{}</fso>'.format(backup_dir))
self.__io.writeln('')
self.__scan_directory_helper(backup_dir, '', csv_writer)
self.progress.finish()

shutil.move(csv_filename1, csv_filename2)
self.__io.writeln('')
self.__io.writeln(' Wrote <fso>{}</fso>'.format(csv_filename2))
self.__io.writeln('')

Expand Down

0 comments on commit 283e732

Please sign in to comment.