We strongly recommend that you regularly back up important files. Backup is usually not limited to user files, but also configuration files, databases, installed software, settings, and even system snapshots.
Here we will guide you through some backup technologies to back up your Raspberry Pi system.
Home folder (Home Directory)
A better method for backing up the home directory is to useTarCommand to generate a directory snapshot compressed file, and then copy it to your PC or cloud storage. Run the following command to back up the home directory:
cd /home/tar czf pi_home.tar.gz pi
Here, a tar compressed file named pi_home.tar.gz is created under the/home/directory. You can copy the file to another device on a USB or network.
MySQL
If you use the MySQL database on Raspberry Pi, it is also important to back up the database. Back up a single database, you can useMysqldumpCommand:
mysqldump recipes > recipes.sql
To restore a database from a backup file, you need to import the backup file in MySQL and provide the certificate (if needed) and database name.
Note that the database must already exist, so create it first:
mysql -Bse "create database recipes"cat recipes.sql | mysql recipes
In addition, you can also use the PV command (not installed by default, you need to useApt-Get install PVCommand installation) view the progress of MySQL's backup file processing. This is useful for large files:
pv recipes | mysql recipes
SD card image (SD card image)
You may need to back up the entire SD card image so that you can recover to the new SD card when the original SD card is lost or damaged. You can back up the SD card by writing the image to the SD card, but in reverse order.
On Linux or MAC systems, for example:
sudo dd bs=4M if=/dev/sdb of=raspbian.img
An image file will be created on your PC. You can write the image file to another SD card to copy the same content and settings. Recover or copy to another SD card.DdCommand, but in turn:
sudo dd bs=4M if=raspbian.img of=/dev/sdb
For more information, see installing SD card imagers.
Automation)
You can write a bash script to automate the execution of these backup operations, or even use cron to regularly execute these operations.
Address: http://www.raspberrypi.org/documentation/linux/filesystem/backup.md
Raspberry Pi backup