Bosse_B
Posts: 836
Joined: Thu Jan 30, 2014 9:53 am

How to backup/restore my RPi4?

Sun Oct 27, 2019 11:35 am

Backup/Restore is creeping up at me now since I am having issues with broken WiFi settings on my RPi4 with 4GB RAM.

I am looking for a way to back up my existing installation and then wipe the SDCard and start over with a new image.
I need to get all of my installed stuff back, except for the changes I did that broke WiFi...
I have saved history to a file so I should be able to go through this and find what if anything needs reinstalling, but edited conf files and such is a different matter.
I am considering to tar the /home/pi, /etc and selected parts of the /var dir and save the tar files to an external NAS.
Then when I get back to a fresh new system I should be able to expand the /home/pi tar file into its correct place, which will bring back the stuff in home.
But how do I handle the general settings and apt installed stuff?
I guess there is no such thing on Raspbian as a Windows type "restore point" to catch changes to the system as opposed to user file changes?

Maybe there is a better way?

In general I should be backing up my stuff more often but what is the recommended "best practice"?

Making an SDCard image at a certain interval as I have read suggestions of seems not to be optimal...
After all I want to get back whatever I work on (typically in /home/pi and /var/www/) as well as the applications installed with apt. And here is the problem because I have no real knowledge of where the apt system stores the applications...
Bo Berglund
Sweden

Kendek
Posts: 128
Joined: Thu Jul 25, 2019 4:39 pm
Location: Kaposvár, Hungary

Re: How to backup/restore my RPi4?

Sun Oct 27, 2019 1:20 pm

Why would you like to wipe the entire SD card after broken WiFi settings?
I'm using the systemback.sh script for backup and restore the system and the user's configuration files. I definitely wouldn't wipe the SD card when I want to try a new stuff inside the OS.

User avatar
rin67630
Posts: 583
Joined: Fri Mar 04, 2016 10:15 am

Re: How to backup/restore my RPi4?

Sun Oct 27, 2019 1:46 pm

If you only have jeopardized the WiFi, you may plug the SD card into another computer (windows may do as well) and create/edit a new wpa_supplicant.conf in the boot partition containing the right credentials.

Code: Select all

country=UK 
update_config=1
ctrl_interface=/var/run/wpa_supplicant

network={
 scan_ssid=1
 ssid="MyNetworkSSID"
 psk="Pa55w0rd1234"
}

Bosse_B
Posts: 836
Joined: Thu Jan 30, 2014 9:53 am

Re: How to backup/restore my RPi4?

Sun Oct 27, 2019 7:37 pm

Kendek wrote:
Sun Oct 27, 2019 1:20 pm
Why would you like to wipe the entire SD card after broken WiFi settings?
I'm using the systemback.sh script for backup and restore the system and the user's configuration files. I definitely wouldn't wipe the SD card when I want to try a new stuff inside the OS.
Well actually what I did was instead the following:
- Created a new fresh Buster SDcard from a download i did today, keeping the old SDcard safe
- Prepared its boot partition so it would start with ssh enabled and wifi through a wpa_supplicant.conf file
- Then started with the new SDcard and went through all of the usual preparations on a new system (raspi-config etc)
- I also fixed the history function such that it would include a timestamp and use a 10 times larger file

Next I put the old SDcard into a USB caddy and inserted into one of the USB3 connectors on the RPi4.
I mounted sda2 (which holds the root file system).

Now I could use the cp -av command to copy over all of the dirs from /home/pi on the old SDcard where I kept my development stuff.

Before I shut down the old SDcard I ran a history to file dump so I copied this too over and there I have a list of all of the commands I have performed on the old pi so I can find the apt install ones and repeat them on this new SDcard.

I hope this will make the new system OK (as it was previous to my failed WiFi Access Point endeavour).

This is yet to be done after having dinner...
Bo Berglund
Sweden

Bosse_B
Posts: 836
Joined: Thu Jan 30, 2014 9:53 am

Re: How to backup/restore my RPi4?

Sun Oct 27, 2019 11:16 pm

I think I am OK now.
What I did:
- Created a new Raspbian machine using a brand new SDcard with a Sept 26 full image
- Logged on via ssh (PuTTY) and did all of the initial config stuff for a new Raspbian instance including upgrading via
sudo apt update
sudo apt upgrade
- Mounted the old SDcard via USB caddy
- Copied most of the /home/pi dir content over from the old to new machine disk
- Used the history dump from the old system to figure out which packages I had installed globally via apt and installed them in the new machine too
- Configured VNC to start a virtual screen as I did on the old Pi and then I could log on to the desktop through VNC.
- Verified that my dev tool IDE starts up properly
- Likewise WiFi, but I already knew this of course

Long and winding road...

Still:
What would be the proper way to take regular backups that include all changed files so they can later be restored also for the operating system?

And is there no way in the GUI of Buster to tell WiFi to disconnect from its connected SSID without forgetting its password?
If I just want Ethernet it seems a roundabout way to forget the entered and cached password...
I see "Turn off WiFi" at the top, is that what I have to do?
Bo Berglund
Sweden

RonR
Posts: 636
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: How to backup/restore my RPi4?

Mon Oct 28, 2019 1:49 am

Bosse_B wrote:
Sun Oct 27, 2019 11:16 pm
What would be the proper way to take regular backups that include all changed files so they can later be restored also for the operating system?

image-backup in Image File Utilities will make an initial full backup which can then be incrementally updated as changes occur. The resulting image file can be restored at any time and will automatically resize itself. image-backup works with SD cards and USB devices.

RossDv8
Posts: 236
Joined: Thu Jan 21, 2016 12:35 pm

Re: How to backup/restore my RPi4?

Mon Oct 28, 2019 4:42 am

This would have been better to know BEFORE you lost settings, but it might be handy. I certainly had no idea about it until I had messed with stuff. So I gather you will have to get all your setting and stuff sorted and install programs anyway.

However, once you have a complete working Raspbian with all your programs installed and any config files etc modified,
Menu > Accessories > SD Card Copier copies the whole thing to a new SD card, including files, folders and documents config files etc.

What surprised me, was that it copied my microSD card to a 240GB SSD and in the case of my Pi 4, all I had to do was make a small 'boot' micrSD and edit one file on that and one file on the SSD to have that. And oddly, I didn;t even have to resize the SSD - it just made use of all available space.

I had already copied everything in my /home/pi folder to a spare drive, and I wish I had known what SD Card Copier was capable of.

Anyway, while it is not a selective backup program or script, it does clone your whole system efficiently from the working microSD to a new microSD card (in an adpater in one of your USB ports).

Then if you break settings, you can insert and boot from the card you cloned, and make sure the relevant setting are working.
Copy any documents and data that have changed to the new card.
Use SD Card Copier to copy the card you have just updated, across to the card with the screwed up settings, which with any luck will give a working backup in case it happens again :D
Remember, nobody is listening to you
until you fart ...

Return to “General discussion”