github.com/mckael/restic@v0.8.3/doc/040_backup.rst (about)

     1  ..
     2    Normally, there are no heading levels assigned to certain characters as the structure is
     3    determined from the succession of headings. However, this convention is used in Python’s
     4    Style Guide for documenting which you may follow:
     5  
     6    # with overline, for parts
     7    * for chapters
     8    = for sections
     9    - for subsections
    10    ^ for subsubsections
    11    " for paragraphs
    12  
    13  ##########
    14  Backing up
    15  ##########
    16  
    17  Now we're ready to backup some data. The contents of a directory at a
    18  specific point in time is called a "snapshot" in restic. Run the
    19  following command and enter the repository password you chose above
    20  again:
    21  
    22  .. code-block:: console
    23  
    24      $ restic -r /tmp/backup backup ~/work
    25      enter password for repository:
    26      scan [/home/user/work]
    27      scanned 764 directories, 1816 files in 0:00
    28      [0:29] 100.00%  54.732 MiB/s  1.582 GiB / 1.582 GiB  2580 / 2580 items  0 errors  ETA 0:00
    29      duration: 0:29, 54.47MiB/s
    30      snapshot 40dc1520 saved
    31  
    32  As you can see, restic created a backup of the directory and was pretty
    33  fast! The specific snapshot just created is identified by a sequence of
    34  hexadecimal characters, ``40dc1520`` in this case.
    35  
    36  If you run the command again, restic will create another snapshot of
    37  your data, but this time it's even faster. This is de-duplication at
    38  work!
    39  
    40  .. code-block:: console
    41  
    42      $ restic -r /tmp/backup backup ~/work
    43      enter password for repository:
    44      using parent snapshot 40dc1520aa6a07b7b3ae561786770a01951245d2367241e71e9485f18ae8228c
    45      scan [/home/user/work]
    46      scanned 764 directories, 1816 files in 0:00
    47      [0:00] 100.00%  0B/s  1.582 GiB / 1.582 GiB  2580 / 2580 items  0 errors  ETA 0:00
    48      duration: 0:00, 6572.38MiB/s
    49      snapshot 79766175 saved
    50  
    51  You can even backup individual files in the same repository.
    52  
    53  .. code-block:: console
    54  
    55      $ restic -r /tmp/backup backup ~/work.txt
    56      scan [/home/user/work.txt]
    57      scanned 0 directories, 1 files in 0:00
    58      [0:00] 100.00%  0B/s  220B / 220B  1 / 1 items  0 errors  ETA 0:00
    59      duration: 0:00, 0.03MiB/s
    60      snapshot 31f7bd63 saved
    61  
    62  In fact several hosts may use the same repository to backup directories
    63  and files leading to a greater de-duplication.
    64  
    65  Please be aware that when you backup different directories (or the
    66  directories to be saved have a variable name component like a
    67  time/date), restic always needs to read all files and only afterwards
    68  can compute which parts of the files need to be saved. When you backup
    69  the same directory again (maybe with new or changed files) restic will
    70  find the old snapshot in the repo and by default only reads those files
    71  that are new or have been modified since the last snapshot. This is
    72  decided based on the modify date of the file in the file system.
    73  
    74  Now is a good time to run ``restic check`` to verify that all data
    75  is properly stored in the repository. You should run this command regularly
    76  to make sure the internal structure of the repository is free of errors.
    77  
    78  You can exclude folders and files by specifying exclude patterns, currently
    79  the exclude options are:
    80  
    81  -  ``--exclude`` Specified one or more times to exclude one or more items
    82  -  ``--exclude-caches`` Specified once to exclude folders containing a special file
    83  -  ``--exclude-file`` Specified one or more times to exclude items listed in a given file
    84  -  ``--exclude-if-present`` Specified one or more times to exclude a folders content
    85     if it contains a given file (optionally having a given header)
    86  
    87  Basic example:
    88  
    89  .. code-block:: console
    90  
    91      $ cat exclude
    92      # exclude go-files
    93      *.go
    94      # exclude foo/x/y/z/bar foo/x/bar foo/bar
    95      foo/**/bar
    96      $ restic -r /tmp/backup backup ~/work --exclude=*.c --exclude-file=exclude
    97  
    98  Please see ``restic help backup`` for more specific information about each exclude option.
    99  
   100  Patterns use `filepath.Glob <https://golang.org/pkg/path/filepath/#Glob>`__ internally,
   101  see `filepath.Match <https://golang.org/pkg/path/filepath/#Match>`__ for syntax.
   102  Patterns are tested against the full path of a file/dir to be saved, not only
   103  against the relative path below the argument given to restic backup.
   104  Patterns need to match on complete path components. (``foo`` matches
   105  ``/dir1/foo/dir2/file`` and ``/dir/foo`` but does not match ``/dir/foobar`` or
   106  ``barfoo``.) A trailing ``/`` is ignored. A leading ``/`` anchors the
   107  pattern at the root directory. (``/bin`` matches ``/bin/bash`` but does not
   108  match ``/usr/bin/restic``.) Regular wildcards cannot be used to match over the
   109  directory separator ``/``. (``b*ash`` matches ``/bin/bash`` but does not match
   110  ``/bin/ash``.) However ``**`` matches arbitrary subdirectories. (``foo/**/bar``
   111  matches ``/dir1/foo/dir2/bar/file``, ``/foo/bar/file`` and ``/tmp/foo/bar``.)
   112  Environment-variables in exclude-files are expanded with
   113  `os.ExpandEnv <https://golang.org/pkg/os/#ExpandEnv>`__.
   114  
   115  By specifying the option ``--one-file-system`` you can instruct restic
   116  to only backup files from the file systems the initially specified files
   117  or directories reside on. For example, calling restic like this won't
   118  backup ``/sys`` or ``/dev`` on a Linux system:
   119  
   120  .. code-block:: console
   121  
   122      $ restic -r /tmp/backup backup --one-file-system /
   123  
   124  By using the ``--files-from`` option you can read the files you want to
   125  backup from a file. This is especially useful if a lot of files have to
   126  be backed up that are not in the same folder or are maybe pre-filtered
   127  by other software.
   128  
   129  or example maybe you want to backup files that have a certain filename
   130  in them:
   131  
   132  .. code-block:: console
   133  
   134      $ find /tmp/somefiles | grep 'PATTERN' > /tmp/files_to_backup
   135  
   136  You can then use restic to backup the filtered files:
   137  
   138  .. code-block:: console
   139  
   140      $ restic -r /tmp/backup backup --files-from /tmp/files_to_backup
   141  
   142  Incidentally you can also combine ``--files-from`` with the normal files
   143  args:
   144  
   145  .. code-block:: console
   146  
   147      $ restic -r /tmp/backup backup --files-from /tmp/files_to_backup /tmp/some_additional_file
   148  
   149  Comparing Snapshots
   150  *******************
   151  
   152  Restic has a `diff` command which shows the difference between two snapshots
   153  and displays a small statistic, just pass the command two snapshot IDs:
   154  
   155  .. code-block:: console
   156  
   157      $ restic -r /tmp/backup diff 5845b002 2ab627a6
   158      password is correct
   159      comparing snapshot ea657ce5 to 2ab627a6:
   160  
   161       C   /restic/cmd_diff.go
   162      +    /restic/foo
   163       C   /restic/restic
   164  
   165      Files:           0 new,     0 removed,     2 changed
   166      Dirs:            1 new,     0 removed
   167      Others:          0 new,     0 removed
   168      Data Blobs:     14 new,    15 removed
   169      Tree Blobs:      2 new,     1 removed
   170        Added:   16.403 MiB
   171        Removed: 16.402 MiB
   172  
   173  
   174  Backing up special items and metadata
   175  *************************************
   176  
   177  **Symlinks** are archived as symlinks, ``restic`` does not follow them.
   178  When you restore, you get the same symlink again, with the same link target
   179  and the same timestamps.
   180  
   181  If there is a **bind-mount** below a directory that is to be saved, restic descends into it.
   182  
   183  **Device files** are saved and restored as device files. This means that e.g. ``/dev/sda`` is
   184  archived as a block device file and restored as such. This also means that the content of the
   185  corresponding disk is not read, at least not from the device file.
   186  
   187  By default, restic does not save the access time (atime) for any files or other
   188  items, since it is not possible to reliably disable updating the access time by
   189  restic itself. This means that for each new backup a lot of metadata is
   190  written, and the next backup needs to write new metadata again. If you really
   191  want to save the access time for files and directories, you can pass the
   192  ``--with-atime`` option to the ``backup`` command.
   193  
   194  Reading data from stdin
   195  ***********************
   196  
   197  Sometimes it can be nice to directly save the output of a program, e.g.
   198  ``mysqldump`` so that the SQL can later be restored. Restic supports
   199  this mode of operation, just supply the option ``--stdin`` to the
   200  ``backup`` command like this:
   201  
   202  .. code-block:: console
   203  
   204      $ mysqldump [...] | restic -r /tmp/backup backup --stdin
   205  
   206  This creates a new snapshot of the output of ``mysqldump``. You can then
   207  use e.g. the fuse mounting option (see below) to mount the repository
   208  and read the file.
   209  
   210  By default, the file name ``stdin`` is used, a different name can be
   211  specified with ``--stdin-filename``, e.g. like this:
   212  
   213  .. code-block:: console
   214  
   215      $ mysqldump [...] | restic -r /tmp/backup backup --stdin --stdin-filename production.sql
   216  
   217  Tags for backup
   218  ***************
   219  
   220  Snapshots can have one or more tags, short strings which add identifying
   221  information. Just specify the tags for a snapshot one by one with ``--tag``:
   222  
   223  .. code-block:: console
   224  
   225      $ restic -r /tmp/backup backup --tag projectX --tag foo --tag bar ~/work
   226      [...]
   227  
   228  The tags can later be used to keep (or forget) snapshots with the ``forget``
   229  command. The command ``tag`` can be used to modify tags on an existing
   230  snapshot.