You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: linux/filesystem/backup.md
+11-12Lines changed: 11 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ Here we'll guide you through some backup techniques for your Raspberry Pi system
8
8
9
9
A sensible way to keep your home folder backed up is to use the `tar` command to make a snapshot archive of the folder, and keep a copy of it on your home PC or in cloud storage. To do this enter the following commands:
10
10
11
-
```
11
+
```bash
12
12
cd /home/
13
13
tar czf pi_home.tar.gz pi
14
14
```
@@ -19,26 +19,26 @@ This creates a tar archive called `pi_home.tar.gz` in `/home/`. You should copy
19
19
20
20
If you have MySQL databases running on your Raspberry Pi, it would be wise to keep them backed up too. To back up a single database, use the `mysqldump` command:
21
21
22
-
```
22
+
```bash
23
23
mysqldump recipes > recipes.sql
24
24
```
25
25
26
26
This command will back up the `recipes` database to the file `recipes.sql`. Note that in this case no username and password have been supplied to the `mysqldump` command. If you do not have your MySQL credentials in a `.my.cnf` configuration file in your home folder, then supply the username and password with flags:
27
27
28
-
```
28
+
```bash
29
29
mysqldump -uroot -ppass recipes > recipes.sql
30
30
```
31
31
32
32
To restore a MySQL database from a dumpfile, pipe the dumpfile into the `mysql` command; provide credentials if necessary and the database name. Note that the database must exist, so create it first:
33
33
34
-
```
34
+
```bash
35
35
mysql -Bse "create database recipes"
36
36
cat recipes.sql | mysql recipes
37
37
```
38
38
39
-
Alternatively, you can use the `pv` command (not installed by default, so install with `apt-get install pv`) to see a progress meter as the dumpfile is processed by MySQL. This is useful for large files:
39
+
Alternatively, you can use the `pv` command (not installed by default, so install with `sudo apt-get install pv`) to see a progress meter as the dumpfile is processed by MySQL. This is useful for large files:
40
40
41
-
```
41
+
```bash
42
42
pv recipes.sql | mysql recipes
43
43
```
44
44
@@ -48,29 +48,28 @@ It may be sensible for you to keep a copy of the entire SD card image, so you ca
48
48
49
49
In Linux or Mac, for example:
50
50
51
-
```
51
+
```bash
52
52
sudo dd bs=4M if=/dev/sdb of=raspbian.img
53
53
```
54
54
55
55
This will create an image file on your PC which you can use to write to another SD card, and keep exactly the same contents and settings. To restore or clone to another card, use `dd` in reverse:
56
56
57
-
```
57
+
```bash
58
58
sudo dd bs=4M if=raspbian.img of=/dev/sdb
59
59
```
60
60
61
61
These files can be very large, and compress well. To compress, you can pipe the output of ```dd``` to ```gzip``` as well to get a compressed file that is significantly smaller than the original size:
62
62
63
-
```
63
+
```bash
64
64
sudo dd bs=4M if=/dev/sdb | gzip > rasbian.img.gz
65
65
```
66
66
67
-
To restore, pipe the output of ```gunzip``` to ```dd```:
0 commit comments