restic/doc/075_scripting.rst

326 lines
16 KiB
ReStructuredText
Raw Normal View History

2018-04-04 14:43:20 +00:00
..
Normally, there are no heading levels assigned to certain characters as the structure is
determined from the succession of headings. However, this convention is used in Pythons
Style Guide for documenting which you may follow:
# with overline, for parts
* for chapters
= for sections
- for subsections
^ for subsubsections
" for paragraphs
#########################
Scripting
#########################
This is a list of how certain tasks may be accomplished when you use
restic via scripts.
Check if a repository is already initialized
********************************************
You may find a need to check if a repository is already initialized,
perhaps to prevent your script from initializing a repository multiple
times. The command ``cat config`` may be used for this purpose:
2018-04-04 14:43:20 +00:00
.. code-block:: console
$ restic -r /srv/restic-repo cat config
Fatal: unable to open config file: stat /srv/restic-repo/config: no such file or directory
2018-04-04 14:43:20 +00:00
Is there a repository at the following location?
2018-04-28 14:19:16 +00:00
/srv/restic-repo
2018-04-04 14:43:20 +00:00
If a repository does not exist, restic will return a non-zero exit code
and print an error message. Note that restic will also return a non-zero
exit code if a different error is encountered (e.g.: incorrect password
to ``cat config``) and it may print a different error message. If there
are no errors, restic will return a zero exit code and print the repository
metadata.
2020-05-16 04:40:09 +00:00
2020-11-26 07:54:53 +00:00
Restic and JSON
2020-05-16 04:40:09 +00:00
***************
Restic can output json data if requested with the ``--json`` flag.
The structure of that data varies depending on the circumstance. The
2020-11-26 07:54:53 +00:00
json output of most restic commands are documented here.
2020-05-16 04:40:09 +00:00
.. note::
Not all commands support json output. If a command does not support json output,
2020-11-26 07:54:53 +00:00
feel free to submit a pull request!
2020-05-16 04:40:09 +00:00
Backup
------
2020-11-26 07:54:53 +00:00
The backup command has multiple json structures, outlined below.
During the backup process, Restic will print out a stream of new-line separated JSON
messages. You can determine the nature of the message by the ``message_type`` field.
2020-05-16 04:40:09 +00:00
Status
^^^^^^
2020-11-26 07:54:53 +00:00
+----------------------+------------------------------------------------------------+
|``message_type`` | Always "status" |
+----------------------+------------------------------------------------------------+
|``seconds_elapsed`` | Time since backup started |
+----------------------+------------------------------------------------------------+
|``seconds_remaining`` | Estimated time remaining |
+----------------------+------------------------------------------------------------+
|``percent_done`` | Percentage of data backed up (bytes_done/total_bytes) |
+----------------------+------------------------------------------------------------+
|``total_files`` | Total number of files detected |
+----------------------+------------------------------------------------------------+
|``files_done`` | Files completed (backed up or confirmed in repo) |
+----------------------+------------------------------------------------------------+
|``total_bytes`` | Total number of bytes in backup set |
+----------------------+------------------------------------------------------------+
|``bytes_done`` | Number of bytes completed (backed up or confirmed in repo) |
+----------------------+------------------------------------------------------------+
|``error_count`` | Number of errors |
+----------------------+------------------------------------------------------------+
|``current_files`` | List of files currently being backed up |
+----------------------+------------------------------------------------------------+
2020-05-16 04:40:09 +00:00
Error
^^^^^
2020-11-26 07:54:53 +00:00
+----------------------+-------------------------------------------+
| ``message_type`` | Always "error" |
+----------------------+-------------------------------------------+
| ``error`` | Error message |
+----------------------+-------------------------------------------+
| ``during`` | What restic was trying to do |
+----------------------+-------------------------------------------+
| ``item`` | Usually, the path of the problematic file |
+----------------------+-------------------------------------------+
2020-05-16 04:40:09 +00:00
Verbose Status
^^^^^^^^^^^^^^
2020-11-26 07:54:53 +00:00
Verbose status is a status line that supplements
2020-05-16 04:40:09 +00:00
+----------------------+-------------------------------------------+
| ``message_type`` | Always "verbose_status" |
+----------------------+-------------------------------------------+
| ``action`` | Either "new", "unchanged" or "modified" |
+----------------------+-------------------------------------------+
| ``item`` | The item in question |
+----------------------+-------------------------------------------+
| ``duration`` | How long it took, in seconds |
+----------------------+-------------------------------------------+
2020-11-26 07:54:53 +00:00
| ``data_size`` | How big the item is |
2020-05-16 04:40:09 +00:00
+----------------------+-------------------------------------------+
| ``metadata_size`` | How big the metadata is |
+----------------------+-------------------------------------------+
2020-11-26 07:54:53 +00:00
| ``total_files`` | Total number of files |
2020-05-16 04:40:09 +00:00
+----------------------+-------------------------------------------+
Summary
^^^^^^^
2020-11-26 07:54:53 +00:00
Summary is the last output line in a successful backup.
2020-05-16 04:40:09 +00:00
+---------------------------+---------------------------------------------------------+
| ``message_type`` | Always "summary" |
+---------------------------+---------------------------------------------------------+
| ``files_new`` | Number of new files |
+---------------------------+---------------------------------------------------------+
| ``files_changed`` | Number of files that changed |
+---------------------------+---------------------------------------------------------+
| ``files_unmodified`` | Number of files that did not change |
+---------------------------+---------------------------------------------------------+
| ``dirs_new`` | Number of new directories |
+---------------------------+---------------------------------------------------------+
| ``dirs_changed`` | Number of directories that changed |
+---------------------------+---------------------------------------------------------+
| ``dirs_unmodified`` | Number of directories that did not change |
+---------------------------+---------------------------------------------------------+
| ``data_blobs`` | Number of data blobs |
+---------------------------+---------------------------------------------------------+
| ``tree_blobs`` | Number of tree blobs |
+---------------------------+---------------------------------------------------------+
| ``data_added`` | Amount of data added, in bytes |
+---------------------------+---------------------------------------------------------+
| ``total_files_processed`` | Total number of files processed |
+---------------------------+---------------------------------------------------------+
| ``total_bytes_processed`` | Total number of bytes processed |
+---------------------------+---------------------------------------------------------+
| ``total_duration`` | Total time it took for the operation to complete |
+---------------------------+---------------------------------------------------------+
2020-11-26 07:54:53 +00:00
| ``snapshot_id`` | The short ID of the new snapshot |
2020-05-16 04:40:09 +00:00
+---------------------------+---------------------------------------------------------+
snapshots
---------
2020-11-26 07:54:53 +00:00
The snapshots command returns a single JSON object, an array with the structure outlined below.
2020-05-16 04:40:09 +00:00
+----------------+------------------------------------------------------------------------+
2020-11-26 07:54:53 +00:00
| ``hostname`` | The hostname of the machine that's being backed up |
2020-05-16 04:40:09 +00:00
+----------------+------------------------------------------------------------------------+
2020-11-26 07:54:53 +00:00
| ``username`` | The username that the backup command was run as |
2020-05-16 04:40:09 +00:00
+----------------+------------------------------------------------------------------------+
2020-11-26 07:54:53 +00:00
| ``excludes`` | A list of paths and globs that were excluded from the backup |
2020-05-16 04:40:09 +00:00
+----------------+------------------------------------------------------------------------+
2020-11-26 07:54:53 +00:00
| ``tags`` | A list of tags for the snapshot in question |
2020-05-16 04:40:09 +00:00
+----------------+------------------------------------------------------------------------+
2020-11-26 07:54:53 +00:00
| ``id`` | The long snapshot ID |
2020-05-16 04:40:09 +00:00
+----------------+------------------------------------------------------------------------+
2020-11-26 07:54:53 +00:00
| ``short_id`` | The short snapshot ID |
2020-05-16 04:40:09 +00:00
+----------------+------------------------------------------------------------------------+
2020-11-26 07:54:53 +00:00
| ``time`` | The timestamp of when the backup was started |
2020-05-16 04:40:09 +00:00
+----------------+------------------------------------------------------------------------+
2020-11-26 07:54:53 +00:00
| ``parent`` | The ID of the previous snapshot |
2020-05-16 04:40:09 +00:00
+----------------+------------------------------------------------------------------------+
2020-11-26 07:54:53 +00:00
| ``tree`` | The ID of the root tree blob |
2020-05-16 04:40:09 +00:00
+----------------+------------------------------------------------------------------------+
2020-11-26 07:54:53 +00:00
| ``paths`` | A list of paths that were included in the backup |
2020-05-16 04:40:09 +00:00
+----------------+------------------------------------------------------------------------+
cat
---
Cat will return data about various objects in the repository, already in json form.
By specifying ``--json``, it will suppress any non-json messages the command generates.
find
----
2020-11-26 07:54:53 +00:00
The find command outputs an array of json objects with matches for your search term. These
matches are organized by snapshot.
2020-05-16 04:40:09 +00:00
2020-11-26 07:54:53 +00:00
Snapshot
^^^^^^^^
+-----------------+----------------------------------------------+
| ``hits`` | The number of matches in the snapshot |
+-----------------+----------------------------------------------+
| ``snapshot`` | The long ID of the snapshot |
+-----------------+----------------------------------------------+
| ``matches`` | Array of JSON objects detailing a match. |
+-----------------+----------------------------------------------+
Match
^^^^^
+-----------------+----------------------------------------------+
| ``path`` | Object path |
+-----------------+----------------------------------------------+
| ``permissions`` | UNIX permissions |
+-----------------+----------------------------------------------+
| ``type`` | what type it is e.g. file, dir, etc... |
+-----------------+----------------------------------------------+
| ``atime`` | Access time |
+-----------------+----------------------------------------------+
| ``mtime`` | Modification time |
+-----------------+----------------------------------------------+
| ``ctime`` | Change time |
+-----------------+----------------------------------------------+
| ``name`` | Object name |
+-----------------+----------------------------------------------+
| ``user`` | Name of owner |
+-----------------+----------------------------------------------+
| ``group`` | Name of group |
+-----------------+----------------------------------------------+
| ``mode`` | UNIX file mode, shorthand of ``permissions`` |
+-----------------+----------------------------------------------+
2020-11-26 08:21:08 +00:00
| ``device_id`` | Unique machine Identifier |
+-----------------+----------------------------------------------+
| ``links`` | Number of hardlinks |
+-----------------+----------------------------------------------+
2020-11-26 07:54:53 +00:00
| ``uid`` | ID of owner |
+-----------------+----------------------------------------------+
| ``gid`` | ID of group |
+-----------------+----------------------------------------------+
| ``size`` | Size of object in bytes |
+-----------------+----------------------------------------------+
2020-05-16 04:40:09 +00:00
key list
--------
2020-11-26 07:54:53 +00:00
The key list command returns an array of objects with the following structure.
2020-05-16 04:40:09 +00:00
+--------------+------------------------------------+
| ``current`` | Is currently used key? |
+--------------+------------------------------------+
| ``id`` | Unique key ID |
+--------------+------------------------------------+
2020-11-26 07:54:53 +00:00
| ``userName`` | User who created it |
2020-05-16 04:40:09 +00:00
+--------------+------------------------------------+
2020-11-26 07:54:53 +00:00
| ``hostName`` | Name of machine it was created on |
2020-05-16 04:40:09 +00:00
+--------------+------------------------------------+
2020-11-26 07:54:53 +00:00
| ``created`` | Timestamp when it was created |
2020-05-16 04:40:09 +00:00
+--------------+------------------------------------+
ls
--
2020-11-26 07:54:53 +00:00
The ls command spits out a series of newline-separated JSON objects,
the nature of which can be determined by the ``struct_type`` field.
2020-05-16 04:40:09 +00:00
snapshot
^^^^^^^^
+-----------------+-------------------------------------+
| ``time`` | Snapshot time |
+-----------------+-------------------------------------+
| ``tree`` | Snapshot tree root |
+-----------------+-------------------------------------+
| ``paths`` | List of paths included in snapshot |
+-----------------+-------------------------------------+
2020-11-26 07:54:53 +00:00
| ``hostname`` | Hostname of snapshot |
2020-05-16 04:40:09 +00:00
+-----------------+-------------------------------------+
2020-11-26 07:54:53 +00:00
| ``username`` | User snapshot was run as |
2020-05-16 04:40:09 +00:00
+-----------------+-------------------------------------+
2020-11-26 08:21:08 +00:00
| ``uid`` | ID of owner |
2020-05-16 04:40:09 +00:00
+-----------------+-------------------------------------+
2020-11-26 08:21:08 +00:00
| ``gid`` | ID of group |
2020-05-16 04:40:09 +00:00
+-----------------+-------------------------------------+
2020-11-26 07:54:53 +00:00
| ``id`` | Snapshot ID, long form |
2020-05-16 04:40:09 +00:00
+-----------------+-------------------------------------+
2020-11-26 07:54:53 +00:00
| ``short_id`` | Snapshot ID, short form |
2020-05-16 04:40:09 +00:00
+-----------------+-------------------------------------+
2020-11-26 07:54:53 +00:00
| ``struct_type`` | Always "snapshot" |
2020-05-16 04:40:09 +00:00
+-----------------+-------------------------------------+
node
^^^^
+-----------------+--------------------------+
2020-11-26 07:54:53 +00:00
| ``name`` | Node name |
2020-05-16 04:40:09 +00:00
+-----------------+--------------------------+
2020-11-26 07:54:53 +00:00
| ``type`` | Node type |
2020-05-16 04:40:09 +00:00
+-----------------+--------------------------+
2020-11-26 07:54:53 +00:00
| ``path`` | Node path |
2020-05-16 04:40:09 +00:00
+-----------------+--------------------------+
2020-11-26 07:54:53 +00:00
| ``uid`` | UID of node |
2020-05-16 04:40:09 +00:00
+-----------------+--------------------------+
2020-11-26 07:54:53 +00:00
| ``gid`` | GID of node |
2020-05-16 04:40:09 +00:00
+-----------------+--------------------------+
2020-11-26 07:54:53 +00:00
| ``size`` | Size in bytes |
2020-05-16 04:40:09 +00:00
+-----------------+--------------------------+
2020-11-26 07:54:53 +00:00
| ``mode`` | Node mode |
2020-05-16 04:40:09 +00:00
+-----------------+--------------------------+
2020-11-26 07:54:53 +00:00
| ``atime`` | Node access time |
2020-05-16 04:40:09 +00:00
+-----------------+--------------------------+
2020-11-26 07:54:53 +00:00
| ``mtime`` | Node modification time |
2020-05-16 04:40:09 +00:00
+-----------------+--------------------------+
2020-11-26 07:54:53 +00:00
| ``ctime`` | Node creation time |
2020-05-16 04:40:09 +00:00
+-----------------+--------------------------+
2020-11-26 07:54:53 +00:00
| ``struct_type`` | Always "node" |
2020-05-16 04:40:09 +00:00
+-----------------+--------------------------+
stats
-----
+----------------------+---------------------------------------------+
| ``total_size`` | Repository size in bytes |
+----------------------+---------------------------------------------+
| ``total_file_count`` | Number of files backed up in the repository |
+----------------------+---------------------------------------------+
2020-11-26 07:54:53 +00:00
| ``total_blob_count`` | Number of blobs in the repository |
+----------------------+---------------------------------------------+