Back Up the Entire Operating System to the Cloud to Prevent SD Card Failure

Back Up the Entire Operating System to the Cloud to Prevent SD Card Failure

I once had the situation where I suddenly woke up one day to find the entire smarthome system completely paralyzed because it could not boot back up. At that moment I wished I could immediately restore the system using the most recent backup file, but unfortunately the last time I ssh'd in to make a backup was 3 months earlier. By then the system had gone through a lot of changes, from software updates to all the configurations I had tweaked during use. I then spent half a day adjusting everything back to how I wanted it.

The article below is a set of solutions for automatically backing up and storing backup files in multiple locations so you can easily access and restore almost all of your data.

Refer to Mega’s direct guide.nz

Install disk backup

Show the list of disks: df -h

cd ~
git clone https://github.com/lzkelley/bkup_rpimage.git

Install backup file shrinking

wget https://raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh
chmod +x pishrink.sh
sudo mv pishrink.sh /usr/local/bin

Fix missing package error on arm64: Reference source

$ wget https://mega.nz/linux/repo/Raspbian_10.0/Release.key && sudo apt-key add Release.key
$ sudo dpkg --add-architecture armhf
$ sudo nano /etc/apt/sources.list.d/mega.nz.list

then pasting the indicated code below:

# Source Repository for Mega-CMD and Mega Desktop (For Raspbian ARM)`
# Updated Mega Repo with 4092 bit Release Key`
deb [arch=armhf] https://mega.nz/linux/repo/Raspbian_10.0/ ./

Install mega-sync:

sudo apt update && sudo apt install megacmd

Log in to Mega

mega-login Email PASS

Set up synchronization

mega-sync /mnt/sda1/Backup /Backup

  • View log: mega-cmd-server --debug-full | tee megacmd.log
  • Grant write permission: sudo chmod 775 /mnt/sda1/Backup

Run backup

sudo sh bkup_rpimage/bkup_rpimage.sh start -c /mnt/sda1/Backup/BPI-Backup-$(date +%Y-%m-%d).img & sudo pishrink.sh /mnt/sda1/Backup/BPI-Backup-$(date +%Y-%m-%d).img
  1. Back up using the script from git
  2. Remove redundant parts to shrink the file

Manage files on Mega

mega-ls
mega-rm -r -f /Backup/BPI-Backup-$(date -d "7 days ago" +%Y-%m-%d).img
Bạn đã đăng ký thành công vào Geek Playground
Tuyệt vời! Tiếp theo, hoàn tất thanh toán để có quyền truy cập đầy đủ vào Geek Playground
Chào mừng trở lại! Bạn đã đăng nhập thành công.
Thành công! Tài khoản của bạn đã được kích hoạt đầy đủ, bạn hiện có quyền truy cập vào tất cả nội dung.
Thành công! Thông tin thanh toán của bạn đã được cập nhật.
Cập nhật thông tin thanh toán không thành công.