L'opinione di Loris Palmerini
un diverso punto vista
  • Degne di Nota
    • Su di me
  • Newsletter
  • Diritto
    • Diritti Umani
    • Giustizia
    • Internazionale
  • Economia
    • Banche
    • Finanza e credito
    • Ambiente
    • Usura Statale
  • Scienza
    • Alimentazione e Salute
    • Tecnologia
    • Salute
    • Vaccinazioni
  • Cultura
    • Storia
    • Venetie
    • Attualità e storia del Popolo Veneto
      • Lingua veneta
    • Lombardo-Veneto
    • Politica
    • Ecologia
  • Politica
  • Vaccini
  • Contatti
  • Privacy & Cookies
  • PayPal Donations
23 Settembre 2008

How to config an automatic backup of an Ubuntu server to an USB external hard disk

Informatica 0

Condividi il pensiero
How to config an automatic backup of an Ubuntu server to an USB external hard disk 

First plug in the disk to an usb port so that Linux mount it.
I read from https://help.ubuntu.com/community/RenameUSBDrive
"Labeled devices that automount will be mounted in the /media directory using their label as the mount point, /media/<label>. ex: /media/my_external"

The usb drive is auto mounted an I find out the device using:
df

or find out the device descriptor with
mount

I see /dev/sdc1 on /media/VERBATIM type vfat (rw)

anyway I can identify my device also if not mounted with 
fdisk -l

My device is /dev/sdc1 and the label is VERBATIM

The USB disk is a VFAT filesystem, and I want to keep it that way .
The backup will be performed by sbackupd, it will do a full backup every 21 days and daily it will do an incremental backup.

Unfortunately, if another external disk is plugged before the mine, the /dev/sdc1  will be another FS of another disk.
This will happen especially if You do not change the label to the disk

The problem is to assure that the usb-disk (Vfat Fs) is mounted correctly before the backup in the right place.
Unfortunately VFAT do not support UUID, so it's not possibile to verify if a Vfat FS is mounted via the "ls -l /dev/disk/by-uuid" command.

Sure We can use the /etc/mtab, but it's possible the fs is mounted in the wrong position due to USB plug-in mechanism.
The problem is that /dev/sdc1 it's not necessary the right disk , especially with a label like "verbatim" 
I should change the label of  the disk to something unique so that  to  assure  sbackupd copy  the data in the right place.
(In theory I should also implement a check and mount every available disk and verify it But I will not do here !)

Below http://embraceubuntu.com/2006/03/01/editing-fat32-partition-labels-using-mtools/

 I  assure a label to the disk

# Install mtools:
sudo apt-get install mtools

#change the label to the disk ( must it be mounted before?)
mlabel -i /dev/sdc1 -s ::SERVERCOPY

Now We should modify  /etc/mtools.conf to specify a windows-like drive letter:

echo "" >> /etc/mtools.conf
echo "# # backup USB  disk" >> /etc/mtools.conf
echo "drive p: file=\"/dev/sdc1\"" >> /etc/mtools.conf
echo "" >> /etc/mtools.conf

The disk is p:

So now verify again the label of the disk

mlabel -s p:
Volume label is SERVERCOPY 

Ok, You should do it, I will not do beacouse I have already configured SBACKUP to copy data in /media/VERBATIM.

So, form now on, please use Your disk label instead of VERBATIM

Now let do the script that will verify /dev/sdc1 is mounted on /media/SERVERCOPY or VERBATIM or whatever is Your disk label.

mount /dev/sdc1 /media/VERBATIM

Now let's do a script that verify all conditions and start sbackup  notice I'm poor in bash

# --------------------- cut the code from here
#!/bin/bash
# Loris Palmerini 2009 - copyright http://www.mozilla.org/MPL/MPL-1.1.html
# This bash script verify that a certain VFat filesystem is mounted in a certain mount point
# Vfat Fs have a label, and on Ubuntu usb disk  it's mount on /media/"label"
# 
# So the mounting is verified also against the label and umounted if mounted elsewhere 
# if it's not possible to mount the FS correctly, send an email to admin
# if correctly mounted start sbackup
# if sbackup is not present , send an email

mountpoint="/media/VERBATIM"; # sbackup is configured for that destination
deviceid="/dev/sdc1";
label="SERVERCOPY";

# the "date" of today in form of YYmmDDhhMMss
todayis=$(date +%Y%m%d%H%M%S)  # See date command

# script to send simple email from here http://theos.in/shell-scripting/send-mail-bash-script/
SUBJECT="Backup filed to mount the device"
FROMEMAIL="server@yourdomain.info"
DESTEMAIL="youremail@adminsite.info"
EMAILMESSAGE="/tmp/emailmessage.txt"
echo "Error in mounting backup FS "$deviceid" on "$mountpoint" with volume label "$label   > $EMAILMESSAGE
echo "Today is "$todayis" . Please verify that the unit is properly connected or backup will not be done" >> $EMAILMESSAGE

# umount device 
if grep $deviceid /etc/mtab > /dev/null 2>&1; then
umount $deviceid
fi 
# umount any device in the mount point 
if grep $mountpoint /etc/mtab > /dev/null 2>&1; then
umount $mountpoint
fi 
# umount the fs if mounted automatically
if grep $label /etc/mtab > /dev/null 2>&1; then
umount $label
fi 

# mount the device on the rigth place
if ! mount -v -t vfat $deviceid $mountpoint > /dev/null 2>&1; then
 #   echo "not able to mount -  send an  email to admin"
 # send an email using /bin/mail
 /usr/sbin/sendmail -f $FROMEMAIL $DESTEMAIL < $EMAILMESSAGE
 exit 1 
fi

# now verify the label of the mounted disk 
commandstring="mlabel -s p:"
X=$($commandstring)
Y=" Volume label is "$label" "
if [ "$X" != "$Y" ]; then
 echo "not able to mount volume label "$label" send an  email to admin"
 # send an email 
 /usr/sbin/sendmail -f $FROMEMAIL $DESTEMAIL < $EMAILMESSAGE
 exit 1 
fi
# Let's verify if sbackup is installed
if [ -x /usr/sbin/sbackupd ]; then 
 /usr/sbin/sbackupd 
else 
 echo "sbackup not found -  send an email using sendmail"
 EMAILMESSAGE="The sbackup utility is not properly installed.Please install it"
#    /usr/sbin/sendmail -f $FROMEMAIL $DESTEMAIL < $EMAILMESSAGE
 exit 1
fi

# --------------- END OF SCRIPT CUT TO HERE

Now , save the file in the root directory , suppose as the name mount_and_sbackup.sh
You can change the /etc/cron.d/sbackup file that way

0 3 * * *       root    if [ -x /root/mount_and_sbackup.sh ]; then /root/mount_and_sbackup; fi;

-------------------------- Loris Palmerini
How-to reference
Little guide to bash
http://www.panix.com/~elflord/unix/bash-tute.html
on exit status
http://tldp.org/LDP/abs/html/exit-status.html
concerning the labelling of a Vfat and fat32 disk
https://help.ubuntu.com/community/RenameUSBDrive 
http://embraceubuntu.com/2006/03/01/editing-fat32-partition-labels-using-mtools/
(Visitato 320 volte, 1 oggi)
Il sito attaccato : non si tocca il 25 aprile A linux script that make a backup of the folder with a different filename each time

Related Posts

Informatica

Come velocizzare il proprio portatile

Condividi il pensiero

Condividi il pensieroGli hard disk, tradizionalmente fatti a dischi rotanti, possono essere sostituiti con i dischi a Stato Solido (SSD) che hanno prestazioni circa 10 volte più veloci. Il segreto della velocità dei tablet sta proprio nell’uso di questi dischi SSD. Il tuo vecchio hard disk può essere sostituito con un disco SSD , oggi […]

Commerciale, Informatica

Un buon server NAS a prezzo conveniente

Condividi il pensiero

Condividi il pensieroIl Buffalo LinkStation LS220D è un NAS ( Network Attached Storage) a doppio alloggio con capacità di accesso a BitTorrent autonoma. I dispositivi NAS permettono di condividere in rete interna tutti i file multimediali e i documenti, in maniera sicura al pari di un server tradizionale . Ma questo NAS permette anche di […]

INGANNO-VODAFONE

commerciale, Consumatori, Informatica

Anche Vodafone si allinea al comportamento SCORRETTO ED INGANNEVOLE degli altri operatori

Condividi il pensiero

Condividi il pensieroCirca due mesi or sono ho ceduto alle lusinghe di Vodafone che mi prometteva 1000 minuti 1000 SMS VERSO TUTTI 10 GigaBytes internet in 4G     Pensavo che con questo avessi risolte tutte le mie necessità, stando io sotto i 500 minuti e i 4 GigaBytes di traffico dati, ed avendo così […]

sophia_square

Economia, Informatica, Politica, Scienza

Gli androidi saranno comuni nelle nostre case entro 20 anni

Condividi il pensiero

Condividi il pensieroSofia, l’androide nel video creato dalla Hanson Robotics, ha chiacchierato con la vicepresidente dell’ONU Amina J Mohammed. Sofia ha detto “Sono qui per aiutare l’umanità a creare il futuro”. Alla richiesta di dare un parere sul problema della mancanza di elettricità ed internet in molte parti del mondo, Sofia ha risposto citando lo […]

Devi accedere per postare un commento.

Cerca nel sito

Siti Consigliati

  • Aggregazione Veneta
  • Istituzioni del Lombardo-Veneto
  • Costumanze Venete

Categorie

Articoli recenti

  • Matteo Bassetti dimostra di non essere un credibile scienziato, ecco perché.
  • Da Sars Cov 2 si guarisce – ecco la posologia
  • COVID-19 – l’inizio di una grande ristrutturazione
  • Giuliani ed altri accusano di frode elettorale e occultamento di prove il Segretario di Stato della Giorgia
  • Il Kraken è stato rilasciato
L'opinione di Loris Palmerini
  • Degne di Nota
    • Su di me
  • Newsletter
  • Diritto
    • Diritti Umani
    • Giustizia
    • Internazionale
  • Economia
    • Banche
    • Finanza e credito
    • Ambiente
    • Usura Statale
  • Scienza
    • Alimentazione e Salute
    • Tecnologia
    • Salute
    • Vaccinazioni
  • Cultura
    • Storia
    • Venetie
    • Attualità e storia del Popolo Veneto
      • Lingua veneta
    • Lombardo-Veneto
    • Politica
    • Ecologia
  • Politica
  • Vaccini
  • Contatti
  • Privacy & Cookies
  • PayPal Donations
Riproduzione interamente Riservata - Loris Palmerini 1995-2020