github.com/advanderveer/restic@v0.8.1-0.20171209104529-42a8c19aaea6/doc/080_examples.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 Examples 15 ######## 16 17 ******************************** 18 Setting up restic with Amazon S3 19 ******************************** 20 21 Preface 22 ======= 23 24 This tutorial will show you how to use restic with AWS S3. It will show you how 25 to navigate the AWS web interface, create an S3 bucket, create a user with 26 access to only this bucket, and finally how to connect restic to this bucket. 27 28 Prerequisites 29 ============= 30 31 You should already have a ``restic`` binary available on your system that you can 32 run. Furthermore, you should also have an account with 33 `AWS <https://aws.amazon.com/>`__. You will likely need to provide credit card 34 details for billing purposes, even if you use their 35 `free-tier <https://aws.amazon.com/free/>`__. 36 37 38 Logging into AWS 39 ================ 40 41 Point your browser to 42 https://console.aws.amazon.com 43 and log in using your AWS account. You will be presented with the AWS homepage: 44 45 .. image:: images/aws_s3/01_aws_start.png 46 :alt: AWS Homepage 47 48 By using the "Services" button in the upper left corder, a menu of all services 49 provided by AWS can be opened: 50 51 .. image:: images/aws_s3/02_aws_menu.png 52 :alt: AWS Services Menu 53 54 For this tutorial, the Simple Storage Service (S3), as well as Identity and 55 Access Management (IAM) are relevant. 56 57 58 Creating the bucket 59 =================== 60 61 First, a bucket to store your backups in must be created. Using the "Services" 62 menu, navigate to S3. In case you already have some S3 buckets, you will see a 63 list of them here: 64 65 .. image:: images/aws_s3/03_buckets_list_before.png 66 :alt: List of S3 Buckets 67 68 Click the "Create bucket" button and choose a name and region for your new 69 bucket. For the purpose of this tutorial, the bucket will be named 70 ``restic-demo`` and reside in Frankfurt. Because the bucket name space is 71 shared among all AWS users, the name ``restic-demo`` may not be available to 72 you. Be creative and choose a unique bucket name. 73 74 .. image:: images/aws_s3/04_bucket_create_start.png 75 :alt: Create a Bucket 76 77 It is not necessary to configure any special properties or permissions of the 78 bucket just yet. Therefore, just finish the wizard without making any further 79 changes: 80 81 .. image:: images/aws_s3/05_bucket_create_review.png 82 :alt: Review Bucket Creation 83 84 The newly created ``restic-demo`` bucket will now appear on the list of S3 85 buckets: 86 87 .. image:: images/aws_s3/06_buckets_list_after.png 88 :alt: List With New Bucket 89 90 Creating a user 91 =============== 92 93 Use the "Services" menu of the AWS web interface to navigate to IAM. This will 94 bring you to the IAM homepage. To create a new user, click on the "Users" menu 95 entry on the left: 96 97 .. image:: images/aws_s3/07_iam_start.png 98 :alt: IAM Home Page 99 100 In case you already have set-up users with IAM before, you will see a list of 101 them here. Use the "Add user" button at the top to create a new user: 102 103 .. image:: images/aws_s3/08_user_list.png 104 :alt: IAM User List 105 106 For this tutorial, the new user will be named ``restic-demo-user``. Feel free to 107 choose your own name that best fits your needs. This user will only ever access 108 AWS through the ``restic`` program and not through the web interface. Therefore, 109 "Programmatic access" is selected for "Access type": 110 111 .. image:: images/aws_s3/09_user_name.png 112 :alt: Choose User Name and Access Type 113 114 During the next step, permissions can be assigned to the new user. To use this 115 user with restic, it only needs access to the ``restic-demo`` bucket. Select 116 "Attach existing policies directly", which will bring up a list of pre-defined 117 policies below. Afterwards, click the "Create policy" button to create a custom 118 policy: 119 120 .. image:: images/aws_s3/10_user_pre_policy.png 121 :alt: Assign a Policy 122 123 A new browser window or tab will open with the policy wizard. In Amazon IAM, 124 policies are defined as JSON documents. For this tutorial, the "Policy 125 Generator" will be used to generate a policy file using a web interface: 126 127 .. image:: images/aws_s3/11_policy_start.png 128 :alt: Create a New Policy 129 130 After invoking the policy generator, you will be presented with a user 131 interface to generate individual permission statements. For restic to work, two 132 such statements must be created. The first statement is set up as follows: 133 134 .. code:: 135 136 Effect: Allow 137 Service: Amazon S3 138 Actions: DeleteObject, GetObject, PutObject 139 Resource: arn:aws:s3:::restic-demo/* 140 141 This statement allows restic to create, read and delete objects inside the S3 142 bucket named ``restic-demo``. Adjust the bucket's name to the name of the bucket 143 you created earlier. Using the "Add Statement" button, this statement can be 144 saved. Now a second statement is created: 145 146 .. code:: 147 148 Effect: Allow 149 Service: Amazon S3 150 Actions: ListBucket 151 Resource: arn:aws:s3:::restic-demo 152 153 Again, substitute ``restic-demo`` with the actual name of your bucket. Note that, 154 unlike before, there is no ``/*`` after the bucket name. This statement allows 155 restic to list the objects stored in the ``restic-demo`` bucket. Again, use "Add 156 Statement" to save this statement. The policy creator interface should now 157 look as follows: 158 159 .. image:: images/aws_s3/12_policy_permissions_done.png 160 :alt: Policy Creator With Two Statements 161 162 Continue to the next step and enter a name and description for this policy. For 163 this tutorial, the policy will be named ``restic-demo-policy``. In this step you 164 can also examine the JSON document created by the policy generator. Click 165 "Create Policy" to finish the process: 166 167 .. image:: images/aws_s3/13_policy_review.png 168 :alt: Policy Review 169 170 Go back to the browser window or tab where you were previously creating the new 171 user. Click the button labeled "Refresh" above the list of policies to make 172 sure the newly created policy is available to you. Afterwards, use the search 173 function to search for the ``restic-demo-policy``. Select this policy using the 174 checkbox on the left. Then, continue to the next step. 175 176 .. image:: images/aws_s3/14_user_attach_policy.png 177 :alt: Attach Policy to User 178 179 The next page will present an overview of the user account that is about to be 180 created. If everything looks good, click "Create user" to complete the process: 181 182 .. image:: images/aws_s3/15_user_review.png 183 :alt: User Creation Review 184 185 After the user has been created, its access credentials will be displayed. They 186 consist of the "Access key ID" (think user name), and the "Secret access key" 187 (think password). Copy these down to a safe place. 188 189 .. image:: images/aws_s3/16_user_created.png 190 :alt: User Credentials 191 192 You have now completed the configuration in AWS. Feel free to close your web 193 browser now. 194 195 196 Initializing the restic repository 197 ================================== 198 199 Open a terminal and make sure you have the ``restic`` binary ready. First, choose 200 a password to encrypt your backups with. In this tutorial, ``apg`` is used for 201 this purpose: 202 203 .. code-block:: console 204 205 $ apg -a 1 -m 32 -n 1 -M NCL 206 I9n7G7G0ZpDWA3GOcJbIuwQCGvGUBkU5 207 208 Note this password somewhere safe along with your AWS credentials. Next, the 209 configuration of restic will be placed into environment variables. This will 210 include sensitive information, such as your AWS secret and repository password. 211 Therefore, make sure the next commands **do not** end up in your shell's 212 history file. Adjust the contents of the environment variables to fit your 213 bucket's name and your user's API credentials. 214 215 .. code-block:: console 216 217 $ unset HISTFILE 218 $ export RESTIC_REPOSITORY="s3:https://s3.amazonaws.com/restic-demo" 219 $ export AWS_ACCESS_KEY_ID="AKIAJAJSLTZCAZ4SRI5Q" 220 $ export AWS_SECRET_ACCESS_KEY="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" 221 $ export RESTIC_PASSWORD="I9n7G7G0ZpDWA3GOcJbIuwQCGvGUBkU5" 222 223 224 After the environment is set up, restic may be called to initialize the 225 repository: 226 227 228 .. code-block:: console 229 230 $ ./restic init 231 created restic backend b5c661a86a at s3:https://s3.amazonaws.com/restic-demo 232 233 Please note that knowledge of your password is required to access 234 the repository. Losing your password means that your data is 235 irrecoverably lost. 236 237 restic is now ready to be used with AWS S3. Try to create a backup: 238 239 .. code-block:: console 240 241 $ dd if=/dev/urandom bs=1M count=10 of=test.bin 242 10+0 records in 243 10+0 records out 244 10485760 bytes (10 MB, 10 MiB) copied, 0,0891322 s, 118 MB/s 245 246 $ ./restic backup test.bin 247 scan [/home/philip/restic-demo/test.bin] 248 scanned 0 directories, 1 files in 0:00 249 [0:04] 100.00% 2.500 MiB/s 10.000 MiB / 10.000 MiB 1 / 1 items ... ETA 0:00 250 duration: 0:04, 2.47MiB/s 251 snapshot 10fdbace saved 252 253 $ ./restic snapshots 254 ID Date Host Tags Directory 255 ---------------------------------------------------------------------- 256 10fdbace 2017-03-26 16:41:50 blackbox /home/philip/restic-demo/test.bin 257 258 A snapshot was created and stored in the S3 bucket. This snapshot may now be 259 restored: 260 261 .. code-block:: console 262 263 $ mkdir restore 264 265 $ ./restic restore 10fdbace --target restore 266 restoring <Snapshot 10fdbace of [/home/philip/restic-demo/test.bin] at 2017-03-26 16:41:50.201418102 +0200 CEST by philip@blackbox> to restore 267 268 $ ls restore/ 269 test.bin 270 271 The snapshot was successfully restored. This concludes the tutorial. 272