Compare commits
11 Commits
master
...
experiment
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2dc965719c | ||
|
|
f7d0bd6558 | ||
|
|
06c7c65420 | ||
|
|
56491b7ab0 | ||
|
|
f13802a62b | ||
|
|
f234853b44 | ||
|
|
7c23f293da | ||
|
|
62667d11f8 | ||
|
|
8681034d63 | ||
|
|
00a8c0e170 | ||
|
|
a90ff2c1f8 |
@@ -11,7 +11,7 @@ Little Backup Box is designed to work with USB sticks as backup media. Theoretic
|
|||||||
|
|
||||||
1. Create a bootable SD card with the latest version of Raspbian Lite for use with Little Backup Box.
|
1. Create a bootable SD card with the latest version of Raspbian Lite for use with Little Backup Box.
|
||||||
2. Make sure that your Raspberry Pi is connected to the internet.
|
2. Make sure that your Raspberry Pi is connected to the internet.
|
||||||
3. Run the following command on the Raspberry Pi: `curl -sSL https://is.gd/littlebackupbox | bash`
|
3. Run the following command on the Raspberry Pi: `curl -sSL https://raw.githubusercontent.com/skidave/little-backup-box/master/install-little-backup-box.sh | bash`
|
||||||
|
|
||||||
Little Backup Box supports three backup modes:
|
Little Backup Box supports three backup modes:
|
||||||
|
|
||||||
|
|||||||
@@ -26,9 +26,12 @@ sudo chmod -R 775 /media/storage
|
|||||||
sudo setfacl -Rdm g:pi:rw /media/storage
|
sudo setfacl -Rdm g:pi:rw /media/storage
|
||||||
|
|
||||||
cd
|
cd
|
||||||
git clone https://github.com/dmpop/little-backup-box.git
|
git clone https://github.com/skidave/little-backup-box.git
|
||||||
cd little-backup-box/fonts
|
cd little-backup-box/fonts
|
||||||
sudo cp -R . /home/pi/.fonts
|
sudo cp -R . /home/pi/.fonts
|
||||||
|
cd ../scripts
|
||||||
|
sudo chmod u+x gpio
|
||||||
|
sudo chmod u+x blink
|
||||||
cd
|
cd
|
||||||
|
|
||||||
HEIGHT=15
|
HEIGHT=15
|
||||||
|
|||||||
25
scripts/blink
Normal file
25
scripts/blink
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
. /home/pi/little-backup-box/scripts/gpio
|
||||||
|
|
||||||
|
function blink()
|
||||||
|
{
|
||||||
|
local pin=$1
|
||||||
|
local speed=$2
|
||||||
|
|
||||||
|
while :
|
||||||
|
do
|
||||||
|
gpio write $pin 1
|
||||||
|
sleep $speed
|
||||||
|
gpio write $pin 0
|
||||||
|
sleep $speed
|
||||||
|
done
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Just invoke our function if the script is called directly
|
||||||
|
if [ "$BASH_SOURCE" == "$0" ]; then
|
||||||
|
gpio mode $1 out
|
||||||
|
blink $@
|
||||||
|
fi
|
||||||
@@ -19,12 +19,29 @@
|
|||||||
|
|
||||||
# Specify devices and their mount points
|
# Specify devices and their mount points
|
||||||
# and other settings
|
# and other settings
|
||||||
STORAGE_DEV="sda1" # Name of the storage device
|
STORAGE_DEV="sdc1" # Name of the storage device
|
||||||
STORAGE_MOUNT_POINT="/media/storage" # Mount point of the storage device
|
STORAGE_MOUNT_POINT="/media/storage" # Mount point of the storage device
|
||||||
CARD_DEV="sdb1" # Name of the storage card
|
CARD_DEV="sd[ab]1" # Name of the storage card
|
||||||
CARD_MOUNT_POINT="/media/card" # Mount point of the storage card
|
CARD_MOUNT_POINT="/media/card" # Mount point of the storage card
|
||||||
SHUTD="5" # Minutes to wait before shutdown due to inactivity
|
SHUTD="5" # Minutes to wait before shutdown due to inactivity
|
||||||
|
|
||||||
|
. /home/pi/little-backup-box/scripts/gpio
|
||||||
|
. /home/pi/little-backup-box/scripts/blink
|
||||||
|
|
||||||
|
|
||||||
|
gpio mode 5 out
|
||||||
|
gpio mode 6 out
|
||||||
|
gpio mode 13 out
|
||||||
|
gpio mode 19 out
|
||||||
|
gpio mode 26 out
|
||||||
|
|
||||||
|
gpio wirte 5 0
|
||||||
|
gpio write 6 0
|
||||||
|
gpio write 13 0
|
||||||
|
gpio write 19 0
|
||||||
|
gpio write 26 0
|
||||||
|
|
||||||
|
|
||||||
# Set the ACT LED to heartbeat
|
# Set the ACT LED to heartbeat
|
||||||
sudo sh -c "echo heartbeat > /sys/class/leds/led0/trigger"
|
sudo sh -c "echo heartbeat > /sys/class/leds/led0/trigger"
|
||||||
|
|
||||||
@@ -33,8 +50,9 @@ sudo shutdown -h $SHUTD "Shutdown is activated. To cancel: sudo shutdown -c"
|
|||||||
|
|
||||||
# Wait for a USB storage device (e.g., a USB flash drive)
|
# Wait for a USB storage device (e.g., a USB flash drive)
|
||||||
STORAGE=$(ls /dev/* | grep "$STORAGE_DEV" | cut -d"/" -f3)
|
STORAGE=$(ls /dev/* | grep "$STORAGE_DEV" | cut -d"/" -f3)
|
||||||
|
#STORAGE=$(lsblk -x SIZE | grep sd[a-z]1 | awk '{print $1}' | sort | head -n 1)
|
||||||
while [ -z "${STORAGE}" ]
|
while [ -z "${STORAGE}" ]
|
||||||
do
|
do
|
||||||
sleep 1
|
sleep 1
|
||||||
STORAGE=$(ls /dev/* | grep "$STORAGE_DEV" | cut -d"/" -f3)
|
STORAGE=$(ls /dev/* | grep "$STORAGE_DEV" | cut -d"/" -f3)
|
||||||
done
|
done
|
||||||
@@ -50,16 +68,19 @@ sudo sh -c "echo timer > /sys/class/leds/led0/trigger"
|
|||||||
sudo sh -c "echo 1000 > /sys/class/leds/led0/delay_on"
|
sudo sh -c "echo 1000 > /sys/class/leds/led0/delay_on"
|
||||||
|
|
||||||
# Wait for a card reader or a camera
|
# Wait for a card reader or a camera
|
||||||
CARD_READER=$(ls /dev/* | grep "$CARD_DEV" | cut -d"/" -f3)
|
# takes first device found
|
||||||
until [ ! -z "$CARD_READER" ]
|
CARD_READER=($(ls /dev/* | grep "$CARD_DEV" | cut -d"/" -f3))
|
||||||
do
|
until [ ! -z "${CARD_READER[0]}" ]
|
||||||
|
do
|
||||||
sleep 1
|
sleep 1
|
||||||
CARD_READER=$(ls /dev/sd* | grep "$CARD_DEV" | cut -d"/" -f3)
|
CARD_READER=($(ls /dev/* | grep "$CARD_DEV" | cut -d"/" -f3))
|
||||||
done
|
done
|
||||||
|
|
||||||
# If the card reader is detected, mount it and obtain its UUID
|
# If the card reader is detected, mount it and obtain its UUID
|
||||||
if [ ! -z "$CARD_READER" ]; then
|
if [ ! -z "${CARD_READER[0]}" ]; then
|
||||||
mount /dev"/$CARD_DEV" "$CARD_MOUNT_POINT"
|
mount /dev"/${CARD_READER[0]}" "$CARD_MOUNT_POINT"
|
||||||
|
|
||||||
|
CARD_COUNT=$(find $CARD_MOUNT_POINT/ -type f | wc -l)
|
||||||
# # Set the ACT LED to blink at 500ms to indicate that the card has been mounted
|
# # Set the ACT LED to blink at 500ms to indicate that the card has been mounted
|
||||||
sudo sh -c "echo 500 > /sys/class/leds/led0/delay_on"
|
sudo sh -c "echo 500 > /sys/class/leds/led0/delay_on"
|
||||||
|
|
||||||
@@ -75,12 +96,85 @@ if [ ! -z "$CARD_READER" ]; then
|
|||||||
|
|
||||||
# Set the backup path
|
# Set the backup path
|
||||||
BACKUP_PATH="$STORAGE_MOUNT_POINT"/"$ID"
|
BACKUP_PATH="$STORAGE_MOUNT_POINT"/"$ID"
|
||||||
|
STORAGE_COUNT=$(find $BACKUP_PATH/ -type f | wc -l)
|
||||||
# Perform backup using rsync
|
# Perform backup using rsync
|
||||||
rsync -ah --exclude "*.id" "$CARD_MOUNT_POINT"/ "$BACKUP_PATH"
|
rsync -avh --info=progress2 --exclude "*.id" "$CARD_MOUNT_POINT"/ "$BACKUP_PATH" &
|
||||||
|
pid=$!
|
||||||
|
|
||||||
# Turn off the ACT LED to indicate that the backup is completed
|
COUNTER=0
|
||||||
sudo sh -c "echo 0 > /sys/class/leds/led0/brightness"
|
while kill -0 $pid 2> /dev/null
|
||||||
|
do
|
||||||
|
STORAGE_COUNT=$(find $BACKUP_PATH/ -type f | wc -l)
|
||||||
|
PERCENT=$(expr 100 \* $STORAGE_COUNT / $CARD_COUNT)
|
||||||
|
sudo sh -c "echo $PERCENT"
|
||||||
|
#IF STATEMENTS HERE FOR LEDS
|
||||||
|
if [ $PERCENT -lt 19 ]; then
|
||||||
|
if [ "$COUNTER" -eq 0 ]; then
|
||||||
|
blink 26 0.25 &
|
||||||
|
blink_pid1=$!
|
||||||
|
COUNTER=$((COUNTER+1))
|
||||||
|
fi
|
||||||
|
|
||||||
|
elif [ $PERCENT -gt 20 ] && [ $PERCENT -lt 39 ]; then
|
||||||
|
kill $blink_pid1 2> /dev/null
|
||||||
|
gpio write 26 1
|
||||||
|
if [ "$COUNTER" -eq 1 ]; then
|
||||||
|
blink 19 0.25 &
|
||||||
|
blink_pid2=$!
|
||||||
|
COUNTER=$((COUNTER+1))
|
||||||
|
fi
|
||||||
|
|
||||||
|
elif [ $PERCENT -gt 40 ] && [ $PERCENT -lt 59 ]; then
|
||||||
|
kill $blink_pid2 2> /dev/null
|
||||||
|
gpio write 26 1
|
||||||
|
gpio write 19 1
|
||||||
|
if [ "$COUNTER" -eq 2 ]; then
|
||||||
|
blink 13 0.25 &
|
||||||
|
blink_pid3=$!
|
||||||
|
COUNTER=$((COUNTER+1))
|
||||||
|
fi
|
||||||
|
elif [ $PERCENT -gt 60 ] && [ $PERCENT -lt 79 ]; then
|
||||||
|
kill $blink_pid3 2> /dev/null
|
||||||
|
gpio write 26 1
|
||||||
|
gpio write 19 1
|
||||||
|
gpio write 13 1
|
||||||
|
if [ "$COUNTER" -eq 3 ]; then
|
||||||
|
blink 6 0.25 &
|
||||||
|
blink_pid4=$!
|
||||||
|
COUNTER=$((COUNTER+1))
|
||||||
|
fi
|
||||||
|
elif [ $PERCENT -gt 80 ] && [ $PERCENT -lt 100 ]; then
|
||||||
|
kill $blink_pid4 2> /dev/null
|
||||||
|
gpio write 26 1
|
||||||
|
gpio write 19 1
|
||||||
|
gpio write 13 1
|
||||||
|
gpio write 6 1
|
||||||
|
if [ "$COUNTER" -eq 4 ]; then
|
||||||
|
blink 5 0.25 &
|
||||||
|
blink_pid5=$!
|
||||||
|
COUNTER=$((COUNTER+1))
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
if [ "$COUNTER" -eq 5 ]; then
|
||||||
|
kill $blink_pid5 2> /dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
gpio write 26 1
|
||||||
|
gpio write 19 1
|
||||||
|
gpio write 13 1
|
||||||
|
gpio write 6 1
|
||||||
|
gpio write 5 1
|
||||||
|
|
||||||
|
sleep 5
|
||||||
|
|
||||||
|
gpio clean 5
|
||||||
|
gpio clean 6
|
||||||
|
gpio clean 13
|
||||||
|
gpio clean 19
|
||||||
|
gpio clean 26
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Shutdown
|
# Shutdown
|
||||||
|
|||||||
55
scripts/gpio
Normal file
55
scripts/gpio
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Utility to control the GPIO pins of the Raspberry Pi
|
||||||
|
# Can be called as a script or sourced so that the gpio
|
||||||
|
# function can be called directly
|
||||||
|
|
||||||
|
function gpio()
|
||||||
|
{
|
||||||
|
local verb=$1
|
||||||
|
local pin=$2
|
||||||
|
local value=$3
|
||||||
|
|
||||||
|
local pins=($GPIO_PINS)
|
||||||
|
if [[ "$pin" -lt ${#pins[@]} ]]; then
|
||||||
|
local pin=${pins[$pin]}
|
||||||
|
fi
|
||||||
|
|
||||||
|
local gpio_path=/sys/class/gpio
|
||||||
|
local pin_path=$gpio_path/gpio$pin
|
||||||
|
|
||||||
|
case $verb in
|
||||||
|
read)
|
||||||
|
cat $pin_path/value
|
||||||
|
;;
|
||||||
|
|
||||||
|
write)
|
||||||
|
sudo sh -c "echo $value > $pin_path/value"
|
||||||
|
;;
|
||||||
|
|
||||||
|
mode)
|
||||||
|
if [ ! -e $pin_path ]; then
|
||||||
|
sudo sh -c "echo $pin > $gpio_path/export"
|
||||||
|
fi
|
||||||
|
sudo sh -c "echo $value > $pin_path/direction"
|
||||||
|
;;
|
||||||
|
|
||||||
|
state)
|
||||||
|
if [ -e $pin_path ]; then
|
||||||
|
local dir=$(cat $pin_path/direction)
|
||||||
|
local val=$(cat $pin_path/value)
|
||||||
|
echo "$dir $val"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
clean)
|
||||||
|
sudo sh -c "echo 0 > $pin_path/value"
|
||||||
|
sudo sh -c "echo $pin > $gpio_path/unexport"
|
||||||
|
;;
|
||||||
|
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# Just invoke our function if the script is called directly
|
||||||
|
if [ "$BASH_SOURCE" == "$0" ]; then
|
||||||
|
gpio $@
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user