Coder Social home page Coder Social logo

makewithoutfail's Introduction

Make Without Fail

Build resilience in Raspberry Pi-based compute infrastructure for makers. Start with setting up Pi to operate off an SSD instead of the conventional SD card. The build resilience by containerizing apps with Docker, automated backups of application data to Cloud and disk imaging.

This note covers automated backups of application data to Cloud with rclone and rsync.

Checklist

Step Instruction
YAML file for IOT stack See Andreas Spiess and Graham Garner here. The application data is mapped to a volumes folder on host machine.
Dropbox mount Use rclone as shown here.
Dropbox mount-point service Use systemd as explained here and here and shown in Exhibit A.
Backup command Use rsync as explained here and shown in Exhibit B.
Backup shell script Use bash script for backup job as explained here and shown in Exhibit C.
Backup automation on task scheduler Use crontab as explained here and shown in Exhibit D.

Exhibit A: Create the rclone.service file in the home directory /home/pi.

# /etc/systemd/system/rclone.service
[Unit]
Description=Dropbox (rclone)
AssertPathIsDirectory=/mnt/dropbox
[Service]
Type=notify
ExecStart=/usr/bin/rclone mount \
    --config /home/pi/.config/rclone/rclone.conf \
    --allow-other \
    --vfs-cache-mode writes \
    --vfs-cache-max-size 100M \
    dropbox: /mnt/dropbox
ExecStop=/bin/fusermount -u /mnt/dropbox
  1. Create in Nano using arrow-keys to navigate, Ctrl-K to cut lines, Ctrl-U to paste, Ctrl-O to save and Ctrl-X to quit.
  2. The important specifications are: --config to point to the rclone.conf file and the mapping from dropbox: to the local /mnt/dropbox.
  3. Place the file in the location: /etc/systemd/system. Use sudo cp to write to this destination.
  4. Start with the following commands:
    1. systemctl start rclone
    2. systemctl enable rclone
  5. Use ls -l to verify that the Dropbox folders show up at the mount location. Note that the files may not show up in the File Explorer (GUI).
  6. In case of any errors, proceed as follows:
    • Grab the error logs with the following command: systemctl status rclone.service > err.txt.
    • Fix the file in the home directory using Nano, then sudo cp to /etc/systemd/system as before.
    • Refresh: systemctl daemon-reload.

Exhibit B: Backup with rsync. 

To backup, use the command as follows:

sudo rsync -avz --delete /home/pi/IOTstack/volumes /mnt/dropbox

To test, execute dry-run as follows:

sudo rsync -avz --delete --dry-run /home/pi/IOTstack/volumes /mnt/dropbox

Exhibit C: Write bash (shell) script 'backup2dropbox.sh' in /home/pi for backup with rsync. Use Nano following guide here.

NOW="$(date)"
echo "Started backup at $NOW"
# sudo rsync -avz --delete --dry-run /home/pi/IOTstack/volumes /mnt/dropbox
sudo rsync -avz --delete /home/pi/IOTstack/volumes /mnt/dropbox
NOW="$(date)"
echo "Ended backup at $NOW"
  • The flags are as follows:
    • -a: save metadata (e.g. ownership) while taking back-up.
    • -v: verbose
    • -z: compress
  • Use --delete to clean up files at the destination that have been removed at the source.
  • Make the shell script executable with chmod as follows:
 chmod 755 /home/pi/backup2dropbox.sh
  • Then test it as follows:
sh /home/pi/backup2dropbox.sh

Exhibit D: Open up crontab as root.

sudo crontab -e

Select Nano as the editor from options presented by the interactive shell. Then add the following line to run the shell script at 4:30 am on the 1st and 15th day of every month and every Friday.

30 4 1,15 * 5 /home/pi/backup2dropbox.sh >> /home/pi/logs/cron.log 2>&1

Make sure to have a logs folder /home/pi/logs. The output will be appended to the log file instead of being sent to standard output. Errors will be sent to standard output. To backup daily, modify as follows:

30 4 * * * /home/pi/backup2dropbox.sh >> /home/pi/logs/cron.log 2>&1

makewithoutfail's People

Contributors

sunbee avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.