skywalker@alderaan:~/your/chef-repo$ knife data bag create --secret-file ~/data_bag_secret_key s3cmd s3cfg
Created data_bag[s3cmd]
Created data_bag_item[s3cfg]
If you get the following error below…
1
ERROR: RuntimeError: Please set EDITOR environment variable
..make sure you export your editor as EDITOR
1
export EDITOR=vim
Verify your encrypted data bag items.
12345678910111213
skywaler@alderaan:~/your/chef-repo$ knife data bag show s3cmd s3cfg
id: s3cfg
s3_access_key:
cipher: aes-256-cbc
encrypted_data: BUNCH_OF_RANDOM_CHARS_HERE
iv: RANDOM_CHARS_HERE
version: 1 s3_secret_key: cipher: aes-256-cbc encrypted_data: BUNCH_OF_RANDOM_CHARS_HERE
iv: RANDOM_CHARS_HERE
version: 1 skywaler@alderaan:~/your/chef-repo$
Now check your decrypted data bag items
1234
skywaler@alderaan:~/your/chef-repo$ knife data bag show –secret-file=/home/you/data_bag_secret_key s3cmd s3cfg
id: s3cfg
s3_access_key: YOUR_ACCESS_KEY_HERE
s3_secret_key: YOUR_SECRET_KEY_HERE
If you made it this far; CONGRATS! You should now be ready to back files up to S3.
So, for example, let’s say you have some backups in /mnt/backups you’d like to tar up and copy to S3.
12
skywalker@alderaan:~# ls /mnt/backups/
backup1.tar.gz backup2.tar.gz
You can tar up your backups like so:
1234567
skywalker@alderaan:~# tar zcvhf /tmp/backups.tar.gz /mnt/backups
tar: Removing leading `/' from member names
/mnt/backups/
/mnt/backups/backup1.tar.gz
/mnt/backups/backup2.tar.gz
jackl0phty:~# ls -alh /tmp/backups.tar.gz
-rw-r--r-- 1 root root 167 Dec 19 19:05 /tmp/backups.tar.gz
As you can see above, this will create a tar archive of the /mnt/backups directory and save it as /tmp/backups.tar.gz.
Next, let’s create an S3 bucket that we can use to copy our backups to like so: