Coder Social home page Coder Social logo

autouploader's Introduction

autouploader

Automatically upload new files in a local folder to (your) cloud

What does this script do?

I wrote this script with one usecase in mind: I have a scanner in my network that scans to a shared Samba folder on my Raspberry Pi smart home server. I was looking for a solution to upload from this server to my remote Nextcloud instance to share the scanned documents with all my devices. There is no auto-syncing command line client for Nextcloud so I built my own solution here.

This script monitors a local folder and moves all new files in this folder to a remote (cloud) location, in my case Nextcloud, while deleting the document locally. You are not limited to Nextcloud though, the script supports everything that rclone supports.

Installation

First you need to install the needed dependencies rclone and inotify. On a Raspbbery Pi running Raspbian this works with APT

sudo apt install rclone inotify-tools git

Next you need to set up a rclone config containing the data needed to reach your remote cloud. You can use rclone config and follow the wizard. This will create a config file in ~/.config/rclone/rclone.conf that should look something like this:

[nextcloud]
type = webdav
url = https://example.com/nextcloud/remote.php/dav/files/user/Path/To/Remote/Folder
vendor = nextcloud
user = user
pass = some_random_encrypted_password

Now we can actually download this script and install it as a service. You will need a user to run this script as. In my example I am using the user scanner here and in the .service file.

# clone this repository locally
sudo git clone https://github.com/Bakan0/autouploader.git /opt/autouploader

# copy your rclone config
sudo cp ~/.config/rclone/rclone.conf /opt/autouploader/rclone.conf

# and update the user rights (and detection location as well, if not already completed)
sudo chown scanner /opt/autouploader/rclone.conf
sudo chown scanner /mnt/usb-scans/

# then install this script as a background service
sudo ln -s /opt/autouploader/autouploader.service /etc/systemd/system/autouploader.service
sudo systemctl daemon-reload

Now before you actually start the script open the autoupload.sh file and update the configuration at the start of the file to your liking. Then we can finally start the script by running these commands.

# start the script at system startup during boot
sudo systemctl enable autouploader.service

# start the script running
sudo systemctl start autouploader.service

# check and make sure the startup worked
sudo systemctl status autouploader.service

# to follow all the logs use
journalctl -u autouploader.service -f

If everything is running fine you can now put files in the watched folder and they should automatically be moved to your Nextcloud instance.

Updating

Updating this script can be easily done via git.

cd /opt/autouploader

# stop the service
sudo systemctl stop autouploader.service

# get the latest version
sudo git pull

# reload the systemd configuration (in case it changed)
sudo systemctl daemon-reload

# restart the service with your new version
sudo systemctl start autouploader.service

# check the status of the program

autouploader's People

Contributors

oliverhi avatar bakan0 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.