Backup Utilities¶
All of the following modules are used for creating backups for files in as painless a way as possible.
backup_nt_and_posix
¶
Backup a directory by appending the date and time and copying over.
Backup NT and Posix¶
Motivation¶
This script aims to be platform agnostic and in the long term will be used on Windows, Linux, Mac and Android systems.
-
pyutil.backup_nt_and_posix.
timestamped_dir
(backup_dir, path='.')[source]¶ Create a backup of a directory. Append date and time to new dir name.
Todo
Change this so that it utilizes
subprocess.check_call()
so we handle return codes in a better way.
rclone
¶
Backup files using rclone.
rclone¶
Requires
rclone, a Golang package.
- Set up a simple single use case backup.
Realistically this should be more of the focus.
However if it’s not, then we could make a
collections.defaultdict
that holds default values for each option. * Actually wouldn’tconfigparser.ConfigParser
make more sense?In addition we could use
collections.ChainMap()
to set precedence ofbackupdir
.Expand
argparse
usage withargparse.fromfile_prefix_chars()
to emulate rsync’s file input.
-
pyutil.rclone.
_dir_checker
(dir_)[source]¶ Check that necessary directories exist.
If the default
dst
doesn’t exist, definitely create it. If the user providedsrc
doesn’t exist, crash without making one.It’s more likely that they typed the src dir incorrectly rather than running the script aware of the fact that it is nonexistent.
-
pyutil.rclone.
rclone_base_case
(src, dst)[source]¶ Base case that all other functions build off of.
This function shouldn’t be executed directly; however, it serves as a good template detailing a function and useful command with parameters that rclone uses.
For example,
--follow
is a flag that has conditionals associated it with it.There are situations in which one wants to follow symlinks and others that they don’t.
This command assumes a use case and configures it rclone for it properly.
Todo
rclone takes an argument for user-agent
-
pyutil.rclone.
run
(cmd, **kwargs)[source]¶ Execute the required command in a subshell.
First the command is splited used typical shell grammer.
A new process is created, and from the resulting subprocess object, the
subprocess.Popen().wait()
.This function returns the return code of split
cmd
, so any non-zero value will lead to aSystemExit
with a passed value ofreturncode
.