mirror of
https://github.com/jayofelony/pwnagotchi.git
synced 2025-07-01 18:37:27 -04:00
Add files via upload
Signed-off-by: wpa-2 <9049886+wpa-2@users.noreply.github.com>
This commit is contained in:
@ -8,9 +8,9 @@ import socket
|
|||||||
|
|
||||||
class AutoBackup(plugins.Plugin):
|
class AutoBackup(plugins.Plugin):
|
||||||
__author__ = 'WPA2'
|
__author__ = 'WPA2'
|
||||||
__version__ = '1.1.1'
|
__version__ = '1.1.3'
|
||||||
__license__ = 'GPL3'
|
__license__ = 'GPL3'
|
||||||
__description__ = 'Backs up files when internet is available, using new file list and options.'
|
__description__ = 'Backs up files when internet is available, with support for excludes.'
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.ready = False
|
self.ready = False
|
||||||
@ -29,11 +29,9 @@ class AutoBackup(plugins.Plugin):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# If no custom command(s) are provided, use the default plain tar command.
|
# If no custom command(s) are provided, use the default plain tar command.
|
||||||
|
# The command includes a placeholder for {excludes} so that if no excludes are set, it will be empty.
|
||||||
if 'commands' not in self.options or not self.options['commands']:
|
if 'commands' not in self.options or not self.options['commands']:
|
||||||
self.options['commands'] = ["tar cf {backup_file} {files}"]
|
self.options['commands'] = ["tar cf {backup_file} {excludes} {files}"]
|
||||||
# For a tar.gz archive, use:
|
|
||||||
# self.options['commands'] = ["tar czf {backup_file} {files}"]
|
|
||||||
|
|
||||||
self.ready = True
|
self.ready = True
|
||||||
logging.info("AUTO-BACKUP: Successfully loaded.")
|
logging.info("AUTO-BACKUP: Successfully loaded.")
|
||||||
|
|
||||||
@ -88,7 +86,7 @@ class AutoBackup(plugins.Plugin):
|
|||||||
|
|
||||||
if not self.is_backup_due():
|
if not self.is_backup_due():
|
||||||
now = time.time()
|
now = time.time()
|
||||||
# Log "backup not due" only once every 60 seconds
|
# Log "backup not due" only once every 60 seconds.
|
||||||
if now - self.last_not_due_logged > 60:
|
if now - self.last_not_due_logged > 60:
|
||||||
logging.info("AUTO-BACKUP: Backup not due yet based on the interval.")
|
logging.info("AUTO-BACKUP: Backup not due yet based on the interval.")
|
||||||
self.last_not_due_logged = now
|
self.last_not_due_logged = now
|
||||||
@ -101,6 +99,14 @@ class AutoBackup(plugins.Plugin):
|
|||||||
return
|
return
|
||||||
files_to_backup = " ".join(existing_files)
|
files_to_backup = " ".join(existing_files)
|
||||||
|
|
||||||
|
# Build excludes string if configured.
|
||||||
|
# Use get() so that if 'exclude' is missing or empty, we default to an empty list.
|
||||||
|
excludes = ""
|
||||||
|
exclude_list = self.options.get('exclude', [])
|
||||||
|
if exclude_list:
|
||||||
|
for pattern in exclude_list:
|
||||||
|
excludes += f" --exclude='{pattern}'"
|
||||||
|
|
||||||
# Get the backup location from config.
|
# Get the backup location from config.
|
||||||
backup_location = self.options['backup_location']
|
backup_location = self.options['backup_location']
|
||||||
|
|
||||||
@ -121,7 +127,7 @@ class AutoBackup(plugins.Plugin):
|
|||||||
|
|
||||||
# Execute each backup command.
|
# Execute each backup command.
|
||||||
for cmd in self.options['commands']:
|
for cmd in self.options['commands']:
|
||||||
formatted_cmd = cmd.format(backup_file=backup_file, files=files_to_backup)
|
formatted_cmd = cmd.format(backup_file=backup_file, files=files_to_backup, excludes=excludes)
|
||||||
logging.info(f"AUTO-BACKUP: Running command: {formatted_cmd}")
|
logging.info(f"AUTO-BACKUP: Running command: {formatted_cmd}")
|
||||||
process = subprocess.Popen(
|
process = subprocess.Popen(
|
||||||
formatted_cmd,
|
formatted_cmd,
|
||||||
|
Reference in New Issue
Block a user