Skip to content

Instantly share code, notes, and snippets.

@corndog2000
Created November 14, 2021 00:43
Show Gist options
  • Save corndog2000/c8d9c1430fee751d13b9b8304d464557 to your computer and use it in GitHub Desktop.
Save corndog2000/c8d9c1430fee751d13b9b8304d464557 to your computer and use it in GitHub Desktop.
Sync an influxdb from a remote host, Rasberry Pi, to local server
#!/bin/bash
echo "Delete old downloaded databases"
sudo rm -r /home/centos/Downloads/influx_temp
echo "Download databases from raspberry pi"
rsync -avzrx -e ssh --rsync-path="sudo rsync" pi@172.30.16.31:/var/lib/influxdb /home/centos/Downloads/influx_temp
echo "Stop the influxdb service so the script can remove current local databases"
sudo systemctl stop influxdb
echo "Remove old local databases"
sudo rm -r /var/lib/influxdb/data/
sudo rm -r /var/lib/influxdb/wal/
sudo rm -r /var/lib/influxdb/meta/
echo "Copy newly downloaded databases to local database locations"
sudo cp -r ~/Downloads/influx_temp/influxdb/data/ /var/lib/influxdb/
sudo cp -r ~/Downloads/influx_temp/influxdb/wal/ /var/lib/influxdb/
sudo cp -r ~/Downloads/influx_temp/influxdb/meta/ /var/lib/influxdb/
echo "Own the new files"
sudo chown -R influxdb:influxdb /var/lib/influxdb/
echo "Restart the influxdb service to load the new databases"
sudo systemctl restart influxdb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment