Difference between revisions of "Auto Update Backup"
m (→External HDD example) |
m |
||
Line 92: | Line 92: | ||
add the following to the end | add the following to the end | ||
− | <pre> 01 4 * * * | + | <pre> 01 4 * * * usr/local/bin/AutoUpdateBackup.sh </pre> |
Your RPi will now auto update and backup at 04:00 every day. | Your RPi will now auto update and backup at 04:00 every day. | ||
+ | == Log File == | ||
+ | Optionally you can output the scripts efforts to a logfile. | ||
+ | |||
+ | Modify your crontab entry to | ||
+ | <pre> | ||
+ | 01 04 * * * /usr/local/bin/AutoUpdateBackup.sh >> /var/log/AutoUpdateBackup.log | ||
+ | </pre> | ||
+ | |||
+ | Create an entry in <code> /etc/logrotate.d</code> to rotate the log files | ||
+ | <pre> | ||
+ | $sudo nano /etc/logrotate.d/rsyslog | ||
+ | </pre> | ||
+ | after the line <code>/var/log/messages</code> add the following | ||
+ | <pre> | ||
+ | /var/log/AutoUpdateBackup.log | ||
+ | </pre> | ||
== References == | == References == | ||
#[http://www.raspberrypi.org/phpBB3/viewtopic.php?p=136912 The Raspberry Pi Backup Thread] | #[http://www.raspberrypi.org/phpBB3/viewtopic.php?p=136912 The Raspberry Pi Backup Thread] | ||
#[http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/ how-do-i-add-jobs-to-cron-under-linux] | #[http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/ how-do-i-add-jobs-to-cron-under-linux] | ||
#[http://raspberrypi.stackexchange.com/questions/5427/can-a-raspberry-pi-be-used-to-create-a-backup-of-itself can-a-raspberry-pi-be-used-to-create-a-backup-of-itself] | #[http://raspberrypi.stackexchange.com/questions/5427/can-a-raspberry-pi-be-used-to-create-a-backup-of-itself can-a-raspberry-pi-be-used-to-create-a-backup-of-itself] |
Revision as of 03:45, 2 June 2013
The goal here is to get a network connected Raspberry Pi to periodically update and backup itself up to an external device or network share.
This is heavily based on the developments presented here [1]
Contents
Installation
Copy the script to the home folder on your Raspberry Pi using wget.
cd ~ wget https://raw.github.com/martinrgmiller/RPiAutoBackup/master/AutoUpdateBackup.sh
Create a Backup Location
This location must not be physically on the Pi's SD card, it should be an external USB drive or other share on your network.
The script supports temporary and direct mounting of a network share. Alternatively you can auto mount the shares. Accessing Network Shares.
You must make sure that the location for the backup file is mounted and writeable.
Setup the script
The header of the script header documents the user defined parameters
# EXTDIR must be external i.e. not on the SD card for example a usb stick or network share # BACKUPDIR is the location to write the backup on EXTDIR # PURGE determines if old backups are deleted before zipping the latest sucessful backup, PURGE=false # CIFSHOST is the optional network share host name or address, comment out to disable mounting a CIFSSHARE # CIFSSHARE is the share on the CIFSHOST, required if CIFSHOST is enabled # CIFSCRED is the local path to the CIFS credentials, required if CIFSHOST is enabled # CIFSUID is the users who has write permissions to CIFSSHARE, required if CIFSHOST is enabled
Edit these as required
CIFS example
EXTDIR=/media/cifstemp/Public BACKUPDIR=$EXTDIR/RPi_autobuild_backup PURGE=false CIFSHOST=//192.168.0.8 CIFSSHARE=Public CIFSCRED=/home/raspberrypi/cifs.cred CIFSUID=raspberrypi
External HDD example
Manually mount your USB drive first.
sudo mkdir /media/usbdrive sudo mount /dev/sda1 /media/usbdrive
Edit the script settings to match
EXTDIR=/media/usbdrive BACKUPDIR=$EXTDIR/RPi_autobuild_backup PURGE=true #CIFSHOST=//192.168.0.8 CIFSSHARE=Public CIFSCRED=/home/raspberrypi/cifs.cred CIFSUID=raspberrypi
Here, CIFS mounting is disabled and PURGE has optionally been set to true to delete old backup off the usb drive due to capacity limitations.
Test the Script
$sudo sh AutoUpdateBackup.sh
Move the script to a better location
Assuming you've resolved all the permissions and the scripts runs, copy the script for local admin use only. This isn't strictly necessary as cron can run a script from anywhere, but its 'neater'.
sudo cp /home/jack/AutoUpdateBackup.sh /usr/local/bin/
Modify the permissions of the script to make it executable
sudo chmod +x /usr/local/bin/AutoUpdateBackup.sh
Setup Cron
Edit /etc/crontab [2]
$sudo crontab -e
add the following to the end
01 4 * * * usr/local/bin/AutoUpdateBackup.sh
Your RPi will now auto update and backup at 04:00 every day.
Log File
Optionally you can output the scripts efforts to a logfile.
Modify your crontab entry to
01 04 * * * /usr/local/bin/AutoUpdateBackup.sh >> /var/log/AutoUpdateBackup.log
Create an entry in /etc/logrotate.d
to rotate the log files
$sudo nano /etc/logrotate.d/rsyslog
after the line /var/log/messages
add the following
/var/log/AutoUpdateBackup.log