Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Setting up directories
- SUBDIR=raspberrypi_backups
- DIR=/mnt/mio/hd/o_chiavetta_usb
- echo "Starting RaspberryPI backup process!"
- # Check if backup directory exists
- if [ ! -d "$DIR" ];
- then
- echo "Backup directory $DIR doesn't exist, creating it now!"
- mkdir $DIR
- fi
- # Create a filename with datestamp for our current backup (without .img suffix)
- OFILE="$DIR/backup_$(date +%d-%m-%Y_%H:%M:%S)"
- # Create final filename, with suffix
- OFILEFINAL=$OFILE.img
- # First sync disks
- sync; sync
- # Shut down some services before starting backup process DA PERSONALIZZARE
- #echo "Stopping some services before backup."
- #service apache2 stop
- #service mysql stop
- #service cron stop
- # Begin the backup process, should take about 1 hour from 8Gb SD card to HDD
- echo "Backing up SD card to USB HDD."
- echo "This will take some time depending on your SD card size and read performance. Please wait..."
- SDSIZE=`blockdev --getsize64 /dev/mmcblk0`;
- pv -tpreb /dev/mmcblk0 -s $SDSIZE | dd of=$OFILE bs=1M conv=sync,noerror iflag=fullblock
- # Wait for DD to finish and catch result
- RESULT=$?
- # Start services again that where shutdown before backup process DA PERSONALIZZARE
- #service apache2 start
- #service mysql start
- #service cron start
- echo "You need to start the stopped services again."
- # If command has completed successfully, delete previous backups and exit
- if [ $RESULT = 0 ];
- then
- echo "Successful backup, previous backup files will be deleted."
- rm -f $DIR/backup_*.tar.gz
- mv $OFILE $OFILEFINAL
- #---------------------------------------------------------------------# SEZIONE RIGUARDANTE LA COMPRESSIONE DEL FILE
- echo "Backup is being tarred. Please wait..."
- tar zcf $OFILEFINAL.tar.gz $OFILEFINAL
- rm -rf $OFILEFINAL
- echo "RaspberryPI backup process completed! FILE: $OFILEFINAL.tar.gz"
- echo "Backup completo, salvato in: /mnt/Ext4/$OFILEFINAL.tar.gz" | mail -s "Transmission" daniloruggeri88@gmail.com
- exit 0
- #---------------------------------------------------------------------# SEZIONE RIGUARDANTE LA COMPRESSIONE DEL FILE END
- # Else remove attempted backup file
- else
- echo "Backup failed! Previous backup files untouched."
- echo "Please check there is sufficient space on the HDD."
- rm -f $OFILE
- echo "RaspberryPI backup process failed!"
- exit 1
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement