Skip to content

Commit

Permalink
Fix export for replace path in the catalog.
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoGuadrini committed Sep 2, 2019
1 parent ed5998a commit 4ac84ee
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 6 deletions.
19 changes: 13 additions & 6 deletions bb.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ def compose_command(flags, host):
command.append('--dry-run')
utility.write_log(log_args['status'], log_args['destination'], 'INFO', 'dry-run mode activate')
if flags.log:
log_path = os.path.join(rpath, 'export.log')
log_path = os.path.join(flags.catalog, 'export.log')
command.append(
'--log-file={0}'.format(log_path)
)
Expand Down Expand Up @@ -1017,7 +1017,7 @@ def parse_arguments():

# Create principal parser
parser_object = argparse.ArgumentParser(prog='bb', description=utility.PrintColor.BOLD + 'Butterfly Backup'
+ utility.PrintColor.END, epilog=check_rsync(),
+ utility.PrintColor.END, epilog=check_rsync(),
parents=[parent_parser])
# Create sub_parser "action"
action = parser_object.add_subparsers(title='action', description='Valid action', help='Available actions',
Expand Down Expand Up @@ -1570,9 +1570,6 @@ def parse_arguments():
catalog_path = os.path.join(args.catalog, '.catalog.cfg')
export_catalog = read_catalog(catalog_path)
if os.path.exists(args.destination):
# Compose command
print_verbose(args.verbose, 'Build a rsync command')
cmd = compose_command(args, None)
# Check one export or all
if args.all:
# Log info
Expand All @@ -1583,6 +1580,9 @@ def parse_arguments():
}
logs = list()
logs.append(log_args)
# Compose command
print_verbose(args.verbose, 'Build a rsync command')
cmd = compose_command(args, None)
# Add source
cmd.append('{}'.format(os.path.join(args.catalog, '')))
# Add destination
Expand All @@ -1592,10 +1592,13 @@ def parse_arguments():
log_args = {
'hostname': export_catalog[args.id]['Name'],
'status': args.log,
'destination': os.path.join(export_catalog[args.id]['Path'], 'export.log')
'destination': os.path.join(args.destination, 'export.log')
}
logs = list()
logs.append(log_args)
# Compose command
print_verbose(args.verbose, 'Build a rsync command')
cmd = compose_command(args, None)
# Check specified argument backup-id
if not export_catalog.has_section(args.id):
print(utility.PrintColor.RED +
Expand All @@ -1620,6 +1623,10 @@ def parse_arguments():
# Start export
cmds.append(' '.join(cmd))
run_in_parallel(start_process, cmds, 1)
if os.path.exists(os.path.join(args.destination, '.catalog.cfg')):
# Migrate catalog to new file system
utility.find_replace(os.path.join(args.destination, '.catalog.cfg'), args.catalog.rstrip('/'),
args.destination.rstrip('/'))
else:
print(utility.PrintColor.RED +
"ERROR: Source or destination path doesn't exist!" + utility.PrintColor.END)
Expand Down
Binary file modified docs/build/doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/build/doctrees/index.doctree
Binary file not shown.
2 changes: 2 additions & 0 deletions docs/build/html/_sources/index.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Backups are organized according to precise cataloguing; this is an example:
│ │ ├─── general.log
│ │ └─── symlink of last backup
├── export.log
├── backup.list
└── .catalog.cfg
Expand All @@ -89,6 +90,7 @@ This is how the operating system sees the backups on the file system:
* **general.log**: if enabled, it is the general log of the machine; contains all the info, warnings and errors generated during the backup.
* **symlink of last backup**: this is a symbolic link of the last backup made. Isn't supported if you use an MS-DOS file system.
* **backup.list**: if enabled, it is the log generated by list operation.
* **export.log**: if enabled, it is the log generated by export operation.
* **.catalog.cfg**: is the log that contains the catalog of all backups. The file is the reference of Butterfly Backup to perform future backups.

.. important::
Expand Down
2 changes: 2 additions & 0 deletions docs/build/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ <h3>Installation<a class="headerlink" href="#installation" title="Permalink to t
│ │ ├─── general.log
│ │ └─── symlink of last backup
├── export.log
├── backup.list
└── .catalog.cfg
</pre></div>
Expand All @@ -233,6 +234,7 @@ <h3>Installation<a class="headerlink" href="#installation" title="Permalink to t
<li><strong>general.log</strong>: if enabled, it is the general log of the machine; contains all the info, warnings and errors generated during the backup.</li>
<li><strong>symlink of last backup</strong>: this is a symbolic link of the last backup made. Isn’t supported if you use an MS-DOS file system.</li>
<li><strong>backup.list</strong>: if enabled, it is the log generated by list operation.</li>
<li><strong>export.log</strong>: if enabled, it is the log generated by export operation.</li>
<li><strong>.catalog.cfg</strong>: is the log that contains the catalog of all backups. The file is the reference of Butterfly Backup to perform future backups.</li>
</ul>
<div class="admonition important">
Expand Down
2 changes: 2 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Backups are organized according to precise cataloguing; this is an example:
│ │ ├─── general.log
│ │ └─── symlink of last backup
├── export.log
├── backup.list
└── .catalog.cfg
Expand All @@ -89,6 +90,7 @@ This is how the operating system sees the backups on the file system:
* **general.log**: if enabled, it is the general log of the machine; contains all the info, warnings and errors generated during the backup.
* **symlink of last backup**: this is a symbolic link of the last backup made. Isn't supported if you use an MS-DOS file system.
* **backup.list**: if enabled, it is the log generated by list operation.
* **export.log**: if enabled, it is the log generated by export operation.
* **.catalog.cfg**: is the log that contains the catalog of all backups. The file is the reference of Butterfly Backup to perform future backups.

.. important::
Expand Down
15 changes: 15 additions & 0 deletions utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ def touch(filename, times=None):
os.utime(filename, times)


def find_replace(filename, text_to_search, replacement_text):
"""
Find and replace word in a text file
:param filename: path of file
:param text_to_search: word to search
:param replacement_text: word to replace
:return: file
"""
import fileinput

with fileinput.FileInput(filename, inplace=True) as file:
for line in file:
print(line.replace(text_to_search, replacement_text), end='')


def write_log(status, log, level, message):
"""
Write custom log in a custom path
Expand Down

0 comments on commit 4ac84ee

Please sign in to comment.