On gmail.com, I see this:
0.38 GB (2%) of 15 GB used
I have 20 GB of my 30 GB partition filled with Ubuntu stuff, but probably only 1 GB of important documents, so why not use this free cloud storage for backup?
Is there already a program to do this? I'll probably write one anyway but wanted to ask before I start.
I also want file compression and segmentation, because some systems have 10 MB attachment limits (like the one at work).
Thanks 🙂
Best Answer
Edit May 7, 2021
Historical posts in next sections
The original part of the answer and first major edit are left intact in the next sections for historical references about trial and error.
April 29, 2021 was the last successful time the older script ran. Starting on April 30, 2021 google started scanning the backup archive to see if any filenames ended with
.exe
,.js
, etc. This caused google to reject the attachment.The solution now is to encrypt the backup archive file with a password.
Updated script
Remember to replace capitalized words below with your real words:
daily-backup.sh
Edit July 9, 2019
Historical post in next section
The original part of the answer is left intact in the next section for historical reference to trial and error
Backup script to create .tar file
This is the current backup script:
Replace
USER_NAME
above with your user name. ReplaceEMAIL_NAME@gamil.com
with your actual gmail address. Change the directory/mnt/e/bin
to the directory you store your bash scripts. Save the file and exit. Then use:This makes the script executable.
Notice how the MBR (Master Boot Record) is saved to backup. A separate earlier step to create
~/.mbr.sav
usingsudo dd ...
is required as described in script comments.Notice the
dpkg --get-selections
line. This creates backs up a list of all installed application names.Simplest way to automate sending email
From Send email alerts using ssmtp we find the simplest way of sending email automated from terminal or script. The installation steps are straight forward:
There is one step not mentioned; Google will send you an email confirming you want to allow a "less secure" application to send mail with your account:
After installing and configuring
ssmpt
one more package is required in order to attach your .tar backup file to an email message:This package contains the program
uuencode
which is need to convert binary files for transmission.Setup
cron
daily to call backup scriptCreate the file
/etc/cron.daily/daily-backup
containing:Save the file, exit and use:
This makes the script executable.
What cron emails you every morning
Every morning after
/etc/cron.daily/daily-backup
is runcron
sends you two emails. One is the backupBackup-YYYY-MM-DD.tar
file which in my case is 5.2 MB that I cannot show you. The other is a listing off all the files in the backup which thetar
command had reported tocron
:Summary
It took a month waiting for an answer and then a month writing an answer but, now the project is finished. Going forward it's simply a matter of adding additional directories to the backup script.
The next project will be a full backup but it is 6 GB large and will be copied to gdrive (Google Drive) because gmail is limited to 25 MB. That script is called
/usr/local/bin/full-backup
and is included here if you are interested:Historical section
This will be more a "journey" than an answer as available options are explored.
Backup what is most important to you first
I have two directories where I have invested most of my time since August 2016:
When I first created a
tar
file (tape archive) using these two directories and tried to email them to myself I received this error:gmail.com won't accept files > 25 MB
How can two directories of scripts written over 10 months be larger than 25 MB? On closer examination they are are > 190 MB. Whhaaatttt?
In turns out to be a single file created for testing purposes:
So delete this test file and rerun the commands:
The first command creates the
.tar
file using one directory of script files and the second appends to the.tar
file using the second directory of script files.The
.tar
file is now a more respectable size of 1.3 MB:The simplest way is to email as an attachment
Now that the
.tar
file is created, simply go intogmail.com
and email the file to yourself as an attachment. In the next step we'll want acron
job that creates the file daily and emails it automatically usingMTA
(Mail Transport Agent). An option needs to be setup in gmail.com to delete all these emails older than 30 days. That way only 400 MB or so of total scripts backups will be stored.Edit June 25, 2017
I discovered tonight some configuration files difficult to backup until I stumbled across this thread. The files in question are in my home directory:
Using the link above I created a script called
~/bin/backup
with:To view what is in the
.tar
archive use the command:Remember to replace "Backup-2017-06-26" with the parameter you used when creating the backup.
Edit July 1, 2017
Similar Q&A was posted in November 2014: Send backup by email with crontab. The accepted answer is included below:
This following command worked for me when I tested in my machine.
So probably the approach to follow will be something like,
I will save the above script as
backup_email.sh
and schedule the cron job as,References