View difference between Paste ID: QF6RVHZ9 and vwgiBMFT
SHOW: | | - or go back to the newest paste.
1
#!/bin/bash
2
3
# Setting up directories
4
SUBDIR=raspberrypi_backups
5
DIR=/mnt/mio/hd/o_chiavetta_usb
6
7
echo "Starting RaspberryPI backup process!"
8
9
10
# Check if backup directory exists
11
if [ ! -d "$DIR" ];
12
   then
13
      echo "Backup directory $DIR doesn't exist, creating it now!"
14
      mkdir $DIR
15
fi
16
17
# Create a filename with datestamp for our current backup (without .img suffix)
18
OFILE="$DIR/backup_$(date +%d-%m-%Y_%H:%M:%S)"
19
20
# Create final filename, with suffix
21
OFILEFINAL=$OFILE.img
22
23
# First sync disks
24
sync; sync
25
26-
# Shut down some services before starting backup process
26+
# Shut down some services before starting backup process DA PERSONALIZZARE 
27
#echo "Stopping some services before backup."
28
#service apache2 stop
29
#service mysql stop
30
#service cron stop
31
32
33
# Begin the backup process, should take about 1 hour from 8Gb SD card to HDD
34
echo "Backing up SD card to USB HDD."
35
echo "This will take some time depending on your SD card size and read performance. Please wait..."
36
SDSIZE=`blockdev --getsize64 /dev/mmcblk0`;
37
pv -tpreb /dev/mmcblk0 -s $SDSIZE | dd of=$OFILE bs=1M conv=sync,noerror iflag=fullblock
38
39
# Wait for DD to finish and catch result
40
RESULT=$?
41
42-
# Start services again that where shutdown before backup process
42+
# Start services again that where shutdown before backup process DA PERSONALIZZARE
43
 
44
#service apache2 start
45
#service mysql start
46
#service cron start
47
48
echo "You need to start the stopped services again."
49
50
51
# If command has completed successfully, delete previous backups and exit
52
if [ $RESULT = 0 ];
53
   then
54
      echo "Successful backup, previous backup files will be deleted."
55
      rm -f $DIR/backup_*.tar.gz
56
      mv $OFILE $OFILEFINAL
57
58
#---------------------------------------------------------------------# SEZIONE RIGUARDANTE LA COMPRESSIONE DEL FILE
59
      echo "Backup is being tarred. Please wait..."
60
      tar zcf $OFILEFINAL.tar.gz $OFILEFINAL
61
      rm -rf $OFILEFINAL
62
      echo "RaspberryPI backup process completed! FILE: $OFILEFINAL.tar.gz"
63
      echo "Backup completo, salvato in: /mnt/Ext4/$OFILEFINAL.tar.gz" | mail -s "Transmission" daniloruggeri88@gmail.com
64
      exit 0
65
#---------------------------------------------------------------------# SEZIONE RIGUARDANTE LA COMPRESSIONE DEL FILE END
66
67
# Else remove attempted backup file
68
   else
69
      echo "Backup failed! Previous backup files untouched."
70
      echo "Please check there is sufficient space on the HDD."
71
      rm -f $OFILE
72
      echo "RaspberryPI backup process failed!"
73
      exit 1
74
fi