lk/data/backups/archives.md

80 lines
1.7 KiB
Markdown
Raw Permalink Normal View History

2022-01-16 18:20:39 +00:00
---
title: "Archives"
tags: [ "Documentation", "tar", "backups" ]
2022-01-16 18:20:39 +00:00
---
# `tar`
2020-01-11 06:07:31 +00:00
## Create
2020-01-11 06:07:31 +00:00
Combine many files and directories into a single t-archive file.
2020-01-11 06:07:31 +00:00
```bash
tar cf "$ARCHIVE".tar $DIR
```
You can remember this with the mnemonic '*C*reate *F*ile'.
2020-01-11 06:07:31 +00:00
Unfortunately, this stores the full file path, so making a tar archive of `/etc/nginx/` will store `etc/nginx` (without the leading `/`.
It's often better to tell tar which path to start from using the `-C` flag.
```bash
tar cf "$ARCHIVE".tar -C /etc/ nginx
```
Check the contents of your archive with:
```bash
tar tf "$ARCHIVE".tar
```
If you want to store 'everything in a directory', then using `*` will not work, because it will target everything in the *current* directory.
Instead, you can store the target in a variable:
```bash
files=$(ls /etc/nginx)
tar cf "$ARCHIVE".tar -C /etc/nginx/ $file
```
## Extract
Extract the tar archive with
> tar xf "$ARCHIVE".tar
You can remember this with the mnemonic 'e*X*tract *F*ile'.
## Compress
Create a zip-compressed archive with the `z` flag.
```bash
tar czf "$ARCHIVE".tgz -C /etc/nginx/ $file
```
You can use any file ending you want, but sane people like to use '.tgz' or '.tar.tgz'.
2020-01-11 06:07:31 +00:00
# 7zip
(also called 'p7zip' or '7z')
2020-01-11 06:07:31 +00:00
Make archive:
2020-01-11 06:07:31 +00:00
```bash
PASSWORD=my_password
```
```bash
7za a -tzip -p$PASSWORD -mem=AES256 $ARCHIVE.zip $FILE_1 $FILE_2
```
2020-01-11 06:07:31 +00:00
Note that people can still see every filename in your archive, and can change those files.
They just can't read the contents.
2020-01-11 06:07:31 +00:00
Unzip:
```bash
7za x archive.zip
```
2020-01-11 06:07:31 +00:00
7zip will open anything: zip-files, rar-files, a tin of beans, *anything*.
However, the extracted tgz files will just be tar files, so you will still need to use tar to extract them (see above).