:py:mod:`wandb_utils.commands.backup`
=====================================
.. py:module:: wandb_utils.commands.backup
Module Contents
---------------
.. py:data:: logger
.. py:class:: PyClone(*, binPath: str = None, binSuffix: str = '', messageBufferSize: int = 5, global_flags: Optional[Dict] = None)
Bases: :py:obj:`pyclone.PyClone`
Same as `pyclone.PyClone` but with some methods overridden.
.. py:attribute:: line
.. py:method:: command(self, action: str, source: str, target: str = '', target_remote: str = '', source_remote: str = '') -> str
.. py:method:: copy(self, source: str, target: str, source_remote: str, target_remote: str) -> None
Copy files from source to dest, skipping already copied.
:param source: Files to transfer.
:type source: :obj:`str`
:param remote: Configured service name.
:type remote: :obj:`str`
:param path: Destination to save to.
:type path: :obj:`str`
.. note::
This is a convenience method that wraps around :any:`PyClone.__launchThread()`.
For more information about this action, please read `rclone's documentation `_.
.. py:method:: move(self, source: str, target: str, source_remote: str, target_remote: str) -> None
.. py:method:: signalsDict(self, k=None)
Used for looking up a signal by its integer or string value, or a dictionary listing of all available signals.
:param k:
:type k: :obj:`int` or :obj:`str`, optional
:returns: Returns a dictionary by default, or the desired signal lookup (`string` if an `integer` is given, or `integer` if a `string` is given).
:rtype: :obj:`int`, :obj:`str`, or :obj:`dict`
.. py:method:: sigTrap(self, sigNum, currFrame)
This serves as the process’ signal trap for several default signals (e.g. `SIGINT` and `SIGTERM`).
While you can override this method, you probably won't ever need to, and can leave this to call upon :any:`PyClone.stop() `.
:param sigNum: Signal number (e.g. `2` for `SIGINT`, or `15` for `SIGTERM`.)
:type sigNum: :obj:`int`
:param currFrame: Python Stack frame.
:type currFrame: :obj:`frame`
.. seealso::
* :any:`PyClone.signalsDict() ` - useful for converting :obj:`sigNum` to a string representation.
.. py:method:: signals(self, cb, *keys)
Bind a callback to an arbitrary number of signals.
:param cb: Callback that's executed when a signal occurs that it's been bound to.
:type cb: :obj:`Function` or :obj:`Method`
:param \*keys: Variable length list of signals to bind callback to.
:type \*keys: :obj:`str`
:returns: `True` if successful, `False` if an error occurs.
:rtype: bool
An example for registering a callback to multiple signals:
.. code-block:: python
def myCallback( self, sigNum, currFrame ):
print( f'My callback received sigNum={ sigNum } and currFrame={ currFrame }' )
pass # END METHOD : My callback
def __init__( self ):
self.signals(
self.myCallback,
'SIGINT', # ^C
'SIGTERM', # `kill procID` or `pkill myApp.py` and systemd's default kill signal.
)
pass # END CONSTRUCTOR
.. seealso::
* :any:`PyClone.sigTrap()`
.. py:method:: addFlag(self, key, value=None)
`Rclone` has **many** `global flags `_ available to every command,
if a flag doesn't have the option for a value, simply leave it unset.
**Examples:**
* Dry run without any changes: ``PyClone.addFlag( 'dry-run' )``
* Throttling your total bandwidth: ``PyClone.addFlag( 'bwlimit', '10M' )``
:param key:
:type key: :obj:`str`
:param value:
:type value: :obj:`str`, optional
.. seealso::
* :any:`PyClone.updateFlag()` to update a flag.
* :any:`PyClone.removeFlag()` to remove a flag.
:returns: `True` if key doesn't exist and has been added, `False` if key already exists and couldn't be added.
:rtype: bool
.. py:method:: removeFlag(self, key)
Removes a global flag that was set with :any:`PyClone.addFlag()`
:param key:
:type key: :obj:`str`
.. seealso::
* :any:`PyClone.addFlag()` to add a flag.
* :any:`PyClone.updateFlag()` to update a flag.
:returns: `True` if key was found and removed, otherwise `False`.
:rtype: bool
.. py:method:: updateFlag(self, key, value=None)
Overwrites a flag that was set with :any:`PyClone.addFlag()`
:param key:
:type key: :obj:`str`
:param value:
:type value: :obj:`str`, optional
.. seealso::
* :any:`PyClone.addFlag()` to add a flag.
* :any:`PyClone.removeFlag()` to remove a flag.
:returns: `True` if :any:`PyClone.removeFlag()` and :any:`PyClone.addFlag()` both returned `True`, otherwise `False`.
:rtype: bool
.. py:method:: binPath(self, binPath=None)
Gets (or if a value is provided, sets) path to rclone binary.
**Examples:**
* Host: ``/usr/bin/env rclone``
* Container: ``docker-compose --no-ansi --file /path/to/docker-compose.yaml run rclone``
:param binPath: Path to rclone binary.
:type binPath: :obj:`str`, optional
:returns: Binary path stored in :any:`PyClone.__binPath()`.
:rtype: str
.. py:method:: stop(self)
Used for shutting down rclone (including interrupting transfers, if needed).
:returns: If a process was successfully spawned, and then successfully shut down with this method, a tuple containing the *exit status* and the *signal status* are returned.
:rtype: :obj:`tuple` or :obj:`None`
.. py:method:: tailing(self)
Used by your program for determining if a loop should continue checking for output from `rclone`, based upon multiple conditions.
An example for continuously printing out data from `rclone`:
.. code-block:: python
while rclone.tailing():
if rclone.readline():
print( rclone.line, flush=True )
time.sleep( 0.5 )
.. seealso::
:any:`PyClone.readline()`
:returns: Returns `True` if a process is still running and there's the potential for messages to be added to the buffer, else this returns `False`.
:rtype: :obj:`bool`
.. py:method:: readline(self)
Mostly used in conjunction with :any:`PyClone.tailing()`, this retrieves the oldest line from :any:`the message buffer ` that's filled by rclone, with a buffer size set when :any:`initializing the class `.
.. seealso::
:any:`PyClone.tailing()`
:returns: Returns `True` if a line was removed from the message buffer and stored in :any:`PyClone.line`, otherwise returns `False`.
:rtype: :obj:`bool`
.. py:method:: clearBuffer(self)
Clear all messages in the buffer that were added by an `rclone` action.
.. py:method:: remotes(self)
Lists configured remotes in `rclone`.
:returns: Dictionary of available remotes, where the key is the name and the value is the type.
:rtype: :obj:`dict`
.. py:method:: ls(self, remote, path='')
List files and directories in a given path. If no path is provided, the root directory of your remote destination will be listed.
:param remote: Name of remote service that's configured in rclone.
:type remote: :obj:`str`
:param path: Remote path to list.
:type path: :obj:`str`, optional
:returns: Files and directories.
:rtype: list
.. py:method:: sync(self, *, source, remote, path)
Make source and dest identical, modifying destination only.
:param source: Files to transfer.
:type source: :obj:`str`
:param remote: Configured service name.
:type remote: :obj:`str`
:param path: Destination to save to.
:type path: :obj:`str`
.. note::
This is a convenience method that wraps around :any:`PyClone.__launchThread()`.
For more information about this action, please read `rclone's documentation `_.
.. py:method:: delete(self, *, remote, path, rmdirs=False)
Remove the contents of path.
:param remote: Configured service name.
:type remote: :obj:`str`
:param path: Destination to delete.
:type path: :obj:`str`
:param rmdirs: If set to `True`, rclone will remove all empty directories.
:type rmdirs: :obj:`bool`
.. seealso::
:any:`PyClone.purge()` for deleting directories.
.. note::
This is a convenience method that wraps around :any:`PyClone.__launchThread()`.
For more information about this action, please read `rclone's documentation `_.
.. py:method:: purge(self, *, remote, path)
Remove the path and all of its contents.
:param remote: Configured service name.
:type remote: :obj:`str`
:param path: Destination to delete.
:type path: :obj:`str`
.. seealso::
:any:`PyClone.delete()` for deleting files.
.. note::
This is a convenience method that wraps around :any:`PyClone.__launchThread()`.
For more information about this action, please read `rclone's documentation `_.
.. py:method:: touch(self, *, remote, path, create=True, timestamp=None)
Create new file or change file modification time.
:param remote: Configured service name.
:type remote: :obj:`str`
:param path: Destination to save to.
:type path: :obj:`str`
:param create: If file doesn't exist, it will be created.
:type create: :obj:`bool`
:param timestamp: If timestamp is provided, it will be converted to UTC and applied to the remote service's path.
:type timestamp: :obj:`str` or :obj:`datetime`
:returns: `True` if successful, `False` if unsuccessful.
:rtype: bool
.. note::
For more information about this action, please read `rclone's documentation `_.
Examples:
.. code-block:: python
# No timezone provided, will use current UTC.
rclone.touch( remote='myGoogleDrive', path='/path/to/file.txt' )
# Date provided, but time (and time zone) has not been. Time is in UTC.
rclone.touch( remote='myGoogleDrive', path='/path/to/file.txt', timestamp='2000-01-01' )
# ISO 8601, in human format with microseconds and without a time zone. Time is in UTC.
rclone.touch( remote='myGoogleDrive', path='/path/to/file.txt', timestamp='2000-01-01 12:34:56.789' )
# ISO 8601, with microseconds and with a time zone. Time is in Arizona's time zone (they don't waste their time on DST).
rclone.touch( remote='myGoogleDrive', path='/path/to/file.txt', timestamp='2000-01-01T12:34:56.789-07:00' )
.. py:function:: copy_to_remote(rclone: pyclone.PyClone, source: pathlib.Path, target: Optional[pathlib.Path] = None, source_remote: Optional[str] = None, target_remote: Optional[str] = None) -> bool
.. py:function:: rclone(ctx: click.Context, include_filter: List[str], exclude_filter: List[str], filter: List[str], dump: List[str]) -> None
Perform operations on remote storage using Rclone.
.. py:function:: copy(rclone: PyClone, source: pathlib.Path, source_remote: str, target: Optional[pathlib.Path], target_remote: str) -> None
Copy from SOURCE to REMOTE:TARGET using rclone.
.. py:function:: move(rclone: PyClone, source: pathlib.Path, source_remote: str, target: Optional[pathlib.Path], target_remote: str) -> None
Copy from SOURCE to REMOTE:TARGET using rclone.