Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. Make your last manual image via Win32DiskImager (if something will going wrong)
- 2. Watch that video until 1:28 and do it: http://www.youtube.com/watch?v=1_qp74VU5ao
- 3. Create a new folder on your Raspi: /home/pi/mynetworkdrive
- 4. Edit the this file: sudo nano /etc/fstab
- 5. Add the following line: //192.168.x.xxx/folder /home/pi/mynetworkdrive cifs guest,_netdev 0 0
- replace 192.168.x.xxx with the actual IP-address of your network drive)
- 6. Mount the new drive: sudo mount /home/pi/mynetworkdrive
- 7. (Reboot your Raspberry PI: sudo reboot (just to make sure… maybe not necessary))
- 8. Place the following script (raspy_back-up.sh) into: home/pi/domoticz/scripts
- 9. Make it executable and…
- 10. …exchange the IPadress with your IPadress
- a. check also if all directories are the same as in the script
- b. check if you need to have pv installed
- c. check if you want to stop and start services
- 11. Save the edited script and start it from PUTTY…
- ----------------------------------------------------------------------
- #!/bin/sh
- # this script will make an image from a raspberry pi SD card without a shut-down
- # back-up image will be stored on a network-drive or a network drive on a WIN7 PC
- # check the path of your virtual network-drive on raspberry -> is it also: /home/pi/mynetworkdrive ???
- # check your path to your scripts on your Raspy -> is it also: /home/pi/domoticz/scripts ???
- # check the services you want to stop during back-up -> here: APACHE2, mysql, crontab
- ipadress="192.168.1.12" # IP adress of network-drive in your LAN
- echo "Starting RaspberryPI backup process!"
- # -------------------------------------------------------------------
- # First check if pv package is installed, if not, install it first
- # pv is not needed if you do not like pv to install remove this part
- # do not forget also to remove the pv row before the dd command
- PACKAGESTATUS=`dpkg -s pv | grep Status`
- if [ "$PACKAGESTATUS" = "Status: install ok installed" ] ; then
- echo "Package 'pv' is installed."
- else
- echo "Package 'pv' is NOT installed."
- echo "Installing package 'pv'. Please wait..."
- sudo apt-get -y install pv
- fi
- # end of pv installation
- # -------------------------------------------------------------------
- # Check if destination network drive is accessable
- echo "Check if destination network drive is accessable."
- echo "Trying to PING network drive on $ipadress."
- ping -c 1 -t 1 $ipadress > /dev/null # PING to static IP
- if [ $? -eq 0 ] ; then # if available in local LAN, then do...
- echo "Network drive found."
- else # not found in LAN
- echo "Back-up not possible. No network-drive found. Check IPadress of your network drive."
- exit 1
- fi
- # check if network drive is mounted
- if [ "`mount | grep /home/pi/mynetworkdrive`" ] ; then
- echo "Network drive is still mounted."
- else
- echo "Mounting network drive."
- sudo mount /home/pi/mynetworkdrive
- fi
- # Create a filename with datestamp for our current backup
- OFILE="/home/pi/mynetworkdrive/backup_$(date +%Y%m%d_%H%M%S).img"
- echo "Generating new back-up file $OFILE"
- # First sync disks
- sync; sync
- # Shut down some services before starting backup process, remove or add services
- echo "Stopping some services before backup."
- sudo service apache2 stop
- sudo service mysql stop
- sudo service cron stop
- # Begin the backup process, should take about 1.5 hour from 16 Gb SD card
- echo "Backing up SD card to WIN7 network drive."
- echo "This will take some time depending on your SD card size and read performance. Please wait..."
- # get SD card size
- SDSIZE=`sudo blockdev --getsize64 /dev/mmcblk0`
- echo "SD card size: $SDSIZE"
- # ---------------------------------------------------------------------------
- # remove this part if you have no pv installed but use the dd part stand alone
- sudo pv /dev/mmcblk0 -s $SDSIZE | sudo dd of=$OFILE bs=1M conv=sync,noerror iflag=fullblock
- # ---------------------------------------------------------------------------
- # use this dd row if you do not want to use pv
- #sudo dd if=/dev/mmcblk0 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, remove or add services
- echo "Start the stopped services again."
- sudo service apache2 start
- sudo service mysql start
- sudo service cron start
- # If command has completed , give a state message
- if [ $RESULT = 0 ];
- then
- echo "Raspberry Pi SD card backup image generated."
- exit 0
- # Else state a failure message
- else
- echo "RaspberryPI backup process failed!"
- exit 1
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement