Ubuntu: Encrypted backup to Google drive


I have a computer that is having serious issues, and I don't know how long it will last. I would like to backup my home directory, and upload it to the cloud like my Google drive, how would I do that?


As @heynnema stated in comments, the best way to do this is probably with a portable hard drive. That being said, I'll give you a couple of options, starting with doing it your way.

Encrypting and Backing up to Google Drive (NOT RECOMMENDED)
Warning: This is going to require that you have enough free space on your disk to duplicated your the contents of your home directory in compressed format

While logged in as the user whose directory you want to backup, open a terminal and preform the following actions:

  • Change to your home directory
    cd ~/
  • Compress the contents of your home directory to an encrypted, compressed file which will be saved in /home. When prompted for a password, use something secure as it will be used to encrypt the compressed backup. Just to be on the safe side, we'll split this up into 1G files as well. I don't know what kind of limit Google puts on the file size.
    sudo tar -cJf - ~/ | gpg2 -c | sudo split -b 1G - ../$USER-home.tar.xz.gpg.
  • At this point, you should have a bunch of files named similarly in /home all named like YOUR-USERNAME-home.tar.xz.gpg.*. If your home directory is a gig or less, there will only be one file. Check to see by running:
    ls /home
  • You can upload each of these files to your Google Drive, assuming you have enough space available to you, and all of the contents will be encrypted!

When you want to pull them back down off of Google drive, save them all to a single directory. Change to that directory in a terminal and run one of the following commands, changing YOUR-USERNAME to the username reflected in the backup files. When a password is requested for decryption, enter the same password that you used to encrypt the backup:

  • Decrypt to compressed tar file:
    cat YOUR-USERNAME-home.tar.gpg.* | gpg -d > /path/to/save/tar/file/YOUR-USERNAME-home.tar.xz
  • Decrypt and decompress right to /home/YOUR-USERNAME:
    cat YOUR-USERNAME-home.tar.gpg.* | gpg -d | tar -xJf -

Backing up to an external hard drive (RECOMMENDED)
Plug in your external drive and run the following command from a terminal:

  • Create an uncompressed, unencrypted backup to your hard drive with permissions preserved regardless of the file system on the hard drive.
    sudo tar -cf /path/to/your/hd/$USER-home.tar ~/

When you're ready to access the backed up files, you can simply open the tar file from the hard drive and copy anything over or extract the entire thing.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »