Skip to content

Commit 2aa16c6

Browse files
committed
Improve organization on all docs
1 parent 2b76c80 commit 2aa16c6

26 files changed

Lines changed: 1557 additions & 1533 deletions

docs/backup/README.md

Lines changed: 0 additions & 100 deletions
This file was deleted.

docs/backup/backup-notes.md

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
# Backup Notes
2+
3+
## Utilities
4+
5+
### Tar
6+
7+
Tar is great for creating archives of multiple directories or files into a single file.
8+
It also supports compression and can be combined with other tools for encryption
9+
and integrity checks.
10+
11+
12+
#### Usage
13+
14+
**Compressing directories into a .txz archive:**
15+
16+
```sh
17+
tar -cJf file.txz /path/to/directorie/1 /path/to/directorie/2
18+
```
19+
20+
- Use "-J" to use the xz protocol.
21+
- Use "-cf" to create a new file.
22+
23+
**Using multithreading compression:**
24+
25+
```sh
26+
tar -cf - /path/to/directorie/1 /path/to/directorie/2 | xz -z -T0 -9 > file.txz
27+
```
28+
29+
- "-T0" uses all available CPU cores.
30+
- "-9" is the maximum compression level.
31+
32+
**Extracting an archive:**
33+
34+
```sh
35+
tar -xJf file.txz
36+
```
37+
38+
### GPG
39+
40+
GPG can be used to encrypt files for secure storage or transfer.
41+
42+
43+
#### Usage
44+
45+
**Create a keypair:**
46+
47+
```sh
48+
gpg --full-generate-key
49+
```
50+
51+
**Get key information:**
52+
53+
```sh
54+
gpg --list-keys
55+
```
56+
57+
For the key ID, use the long format (16 characters).
58+
59+
```sh
60+
gpg --list-keys --keyid-format LONG
61+
```
62+
63+
**Export public key:**
64+
65+
```sh
66+
gpg --export --armor <recipient_key_id> > publickey.asc
67+
```
68+
69+
**Import public key:**
70+
71+
```sh
72+
gpg --import publickey.asc
73+
```
74+
75+
**Export secret key for backup:**
76+
77+
```sh
78+
gpg -o private-backup.gpg --export-options backup --export-secret-keys <email_or_key_id>
79+
```
80+
81+
**Import the backup key:**
82+
83+
```sh
84+
gpg --import-options restore --import private-backup.gpg
85+
86+
gpg --edit-key username@example.com
87+
88+
> trust
89+
> 5 (ultimately)
90+
> save
91+
```
92+
93+
**Encrypt a file with a recipient**
94+
95+
```sh
96+
gpg --encrypt --recipient <recipient_key_id> file
97+
```
98+
99+
**Decrypt a file**
100+
101+
```sh
102+
gpg --decrypt file.gpg > file
103+
```
104+
105+
**Encrypt a file with password**
106+
107+
```sh
108+
gpg --encrypt --symmetric file
109+
```
110+
111+
### Rsync
112+
113+
Rsync is a powerful tool for synchronizing files and directories between two locations,
114+
either locally or over a network.
115+
116+
#### Usage
117+
118+
```sh
119+
rsync -arzuvhP /path/to/source /path/to/destiny
120+
```
121+
122+
- "a" for archive mode
123+
- "r" for recursive
124+
- "z" for compression on transit (useful in network)
125+
- "u" for skipping files newer on receiver
126+
- "v" for verbose
127+
- "h" for human readable
128+
- "P" for progress
129+
130+
- "c" for checksum
131+
- "i" for showing changes in a verbose mode
132+
133+
- "--ignore-existing" for leaving untouched the files on destination
134+
- "-delete" for deleting files on destination
135+
136+
> "-n" for dry run
137+
138+
When using -i (--itemize-changes) the output of the changes will be
139+
more verbose of why the changes are being done, running it with
140+
--dry-run is a secure practice in case you want to use -delete, the
141+
output description is:
142+
143+
```sh
144+
YXcstpoguax path/to/file
145+
|||||||||||
146+
`----------- the type of update being done::
147+
|||||||||| <: file is being transferred to the remote host (sent).
148+
|||||||||| >: file is being transferred to the local host (received).
149+
|||||||||| c: local change/creation for the item, such as:
150+
|||||||||| - the creation of a directory
151+
|||||||||| - the changing of a symlink,
152+
|||||||||| - etc.
153+
|||||||||| h: the item is a hard link to another item (requires --hard-links).
154+
|||||||||| .: the item is not being updated (though it might have attributes that are being modified).
155+
|||||||||| *: means that the rest of the itemized-output area contains a message (e.g. "deleting").
156+
||||||||||
157+
`---------- the file type:
158+
||||||||| f for a file,
159+
||||||||| d for a directory,
160+
||||||||| L for a symlink,
161+
||||||||| D for a device,
162+
||||||||| S for a special file (e.g. named sockets and fifos).
163+
|||||||||
164+
`--------- c: different checksum (for regular files)
165+
|||||||| changed value (for symlink, device, and special file)
166+
`-------- s: Size is different
167+
`------- t: Modification time is different
168+
`------ p: Permission are different
169+
`----- o: Owner is different
170+
`---- g: Group is different
171+
`--- u: The u slot is reserved for future use.
172+
`-- a: The ACL information changed
173+
```
174+
175+
### Btrfs
176+
177+
Btrfs is a modern filesystem that supports advanced features like snapshots,
178+
subvolumes, and built-in RAID support. It is well-suited for backup solutions
179+
due to its snapshot capabilities and efficient storage management.
180+
181+
#### Usage
182+
183+
**Format a partition with Btrfs:**
184+
185+
``` bash
186+
sudo mkfs.btrfs /dev/sdXn
187+
```
188+
189+
**To mount a Btrfs filesystem:**
190+
191+
``` bash
192+
sudo mount -o options -t btrfs /dev/sdXn /mnt/point
193+
```
194+
195+
Options can include:
196+
197+
- "compress=zstd" for compression (also supported: lzo, zlis)
198+
- "noatime" to disable access time updates
199+
- "subvol=subvolume_name" to mount a specific subvolume
200+
- "space_cache=v2" for improved space cache management
201+
- "autodefrag" to enable automatic defragmentation
202+
203+
**Taking a snapshot:**
204+
205+
``` bash
206+
sudo btrfs subvolume snapshot -r /mnt/point/subvolume /mnt/point/snapshot_name
207+
```
208+
209+
**Sending a snapshot to another location:**
210+
211+
``` bash
212+
sudo btrfs send /mnt/point/snapshot_name | sudo btrfs receive /mnt/dest/point
213+
```
214+
215+
**Sending an incremental snapshot:**
216+
217+
``` bash
218+
sudo btrfs send -p /mnt/point/snapshot_previous /mnt/point/snapshot_new | sudo btrfs receive /mnt/dest/point
219+
```
220+
221+
**Delete a snapshot:**
222+
223+
``` bash
224+
sudo btrfs subvolume delete /mnt/point/snapshot_name
225+
```
Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ Owner only read and write
6666
umask 177
6767
```
6868

69+
### Find
70+
71+
Find is a very useful command to search files and
72+
execute commands on them.
73+
74+
**Find all `.log` files and delete them**
75+
76+
```sh
77+
find /path/to/search -type f -name "*.log" -exec rm -f {} \;
78+
```
79+
6980
## VIM notes
7081

7182
You can use regex expressions on vim, for example,
@@ -94,37 +105,3 @@ You can also snigger by typing `:Sex` to invoke a horizontal split.
94105
4. Press d to cut (or y to copy).
95106
5. Move to where you would like to paste.
96107
6. Press P to paste before the cursor, or p to paste after.
97-
98-
## GPG notes
99-
100-
To export secret key for backup
101-
102-
```sh
103-
gpg -o private-backup.gpg --export-options backup --export-secret-keys username@example.com
104-
```
105-
106-
And to import the backup key
107-
108-
```sh
109-
gpg --import-options restore --import private.gpg
110-
111-
gpg --edit-key username@example.com
112-
113-
> trust
114-
> 5 (ultimately)
115-
> save
116-
```
117-
118-
## SSH notes
119-
120-
Generate safe ssh key pair
121-
122-
```sh
123-
ssh-keygen -o -a 100 -t ed25519 -f ~/.ssh/id_ed25519 -C "user@email.com"
124-
```
125-
126-
Add a password to an existing key
127-
128-
```sh
129-
ssh-keygen -p -f keyfile
130-
```

0 commit comments

Comments
 (0)