Compare commits

...

4 Commits

2 changed files with 22 additions and 9 deletions

View File

@ -26,3 +26,6 @@ This will allow you to restore a file on disk to the specific version that is st
### Get
The utility will allow you to get the contents of a backup up file and have it output to the terminal.
### Delete
The utility allows you to delete entries/backups in the bucket if you choose to do so.

View File

@ -15,11 +15,11 @@ def usage
#{__FILE__} [ACTION <arg>] [<flags>]
Description:
This utlity is meant to be used to interact with & manage the filebucket on P4 nodes due to the
utility for that `puppet filebucket -l <action>` being nonfunctional.
This utlity is meant to be used to interact with & manage the filebucket in the same capacity as
the builtin filebucket utility. However, it does not handle any puppet tie ins.
This implements the same functionality (minus the puppet tie-in) and will allow the user to
search the filebucket and restore from it.
I created this due to the puppet filebucket utility in my companies P4 envrionments not
functioning
Actions:
search <term> : Search for bucket entries matching a portion of the filepath
@ -568,6 +568,10 @@ def get_entry_by_file (bucket, filenames)
end
end
if $CONFIG[:alt_filepath] != ""
return entry, $CONFIG[:alt_filepath]
end
if filename[0] != '/'
filename = "/#{filename}"
end
@ -578,6 +582,12 @@ end
def get_entry_by_hash (bucket)
if bucket.entries.has_key? $CONFIG[:search_term]
entry = bucket.entries[$CONFIG[:search_term]]
if $CONFIG[:alt_filepath] != ""
log "$CONFIG[:alt_filepath] was set. Skipping prompts asking for filepaths"
return entry, $CONFIG[:alt_filepath]
end
filepath = ""
if entry.filepaths.count == 1
filepath = entry.filepaths[0]
@ -605,10 +615,6 @@ def restore_entry (bucket)
entry, filepath = get_entry_by_hash bucket
end
if $CONFIG[:alt_filepath] != ""
filepath=$CONFIG[:alt_filepath]
end
if get_verification "Are you sure you want to overwrite #{filepath}?"
File.open(filepath,'w') do |file|
file.write(entry.content)
@ -705,15 +711,19 @@ def delete_entry (bucket)
entry = bucket.entries[$CONFIG[:search_term]]
else
puts "BucketEntry[#{$CONFIG[:search_term]}] Does not exist. Please make sure you provided the correct hash value"
exit
end
puts "Corresponding Entry: #{entry.info}"
if get_verification "Are you sure you want to delete BucketEntry[#{entry.hash}]? "
if get_verification "This cannot be undone. Are you sure you want to continue?: "
entry.delete
if entry.delete
puts "Ok. BucketEntry[#{entry.hash}] Has been deleted"
end
end
end
end
# END: Work Functions