Backup Linux - JohnnyFoulds/firstrepo GitHub Wiki
This page describe how the backup your Linux system to Google Drive with the help of the gdrive command line utility.
Install Google Drive CLI
wget -O drive https://drive.google.com/uc?id=0B3X9GlR6EmbnMHBMVWtKaEZXdDg
mv drive /usr/sbin/drive
chmod 755 /usr/sbin/drive
drive
When you run the drive
utility you will be provided with a URL to generate a security code you must then paste back to authenticate gdrive
.
Backup the boot partition
The following command do a backup of the boot partition directly to Google Drive:
BOOTDRIVE="$(fdisk -l | grep '^/dev/[a-z]*[0-9]' | awk '$2 == "*"' | cut -d ' ' -f 1)"
sudo dd conv=sparse if=${BOOTDRIVE} | gzip -c --fast | drive upload --stdin --title bootdrive.gz
Backup the Linux Installation
cd /
sudo tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz --one-file-system /
The --one-file-system
flag ensures that files different filesystem are not included, for example files mounted to external drives or network drives.
Once the backup completes it can then be uploaded to Google Drive:
drive upload -f backup.tar.gz
Restoring
You will want to restore from a Live CD. If needed, first partition and format the drive. You can do this with gparted. Then simply mount the partition you are going to restore somewhere. If you open the drive in the file explorer, it will be auto mounted somewhere under /media. Take a look to find out where with:
ls /media
Then restore the backup with:
sudo tar -xvpzf /path/to/backup.tar.gz -C /media/[MOUNT_POINT] --numeric-owner
Restoring GRUB
For the system to boot, you will need to restore grub. To do this, you will need to reconfigure it in a chroot:
sudo -s
for f in dev dev/pts proc ; do mount --bind /$f /media/[MOUNT_POINT]/$f ; done
chroot /media/[MOUNT_POINT]
dpkg-reconfigure grub-pc
You will get a menu asking you what drive(s) grub should be installed on. Choose whatever drive(s) the computer will be booting from.
Read-Only File System
If you have a problem where the system boots but the file system is read-only perform the following steps:
- Reboot and hold down the
Shift
key to open the GRUB menu. - Choose
Advanced Options
thee
to edit the commands. - Where the file system is
ro
change it torw
. images/GRUB.png - Press
F10
to boot. - The system should boot normally and you can log in.
- See what the uuid of the boot disk is with
ls -l /dev/disk/by-uuid
- Edit the
/etc/fstab
file if it is not correct. - Reboot the system
Web References
- Backup Linux Servers to Google Drive - https://www.experts-exchange.com/articles/29279/Backup-Linux-Servers-to-Google-Drive.html
- BackupYourSystem/TAR - https://help.ubuntu.com/community/BackupYourSystem/TAR
- Bash script to backup data to google drive [duplicate] - https://stackoverflow.com/questions/33063673/bash-script-to-backup-data-to-google-drive
- How do I change file system in recovery mode to read-write mode? - https://askubuntu.com/questions/117950/how-do-i-change-file-system-in-recovery-mode-to-read-write-mode
- after 18.04 install, read-only file system - https://ubuntuforums.org/showthread.php?t=2394477
- Permanent GRUB edit from RO to RW - https://askubuntu.com/questions/468846/permanent-grub-edit-from-ro-to-rw/570873
- How to Configure the GRUB2 Boot Loader’s Settings - https://www.howtogeek.com/196655/how-to-configure-the-grub2-boot-loaders-settings/