A practical guide to moving your monitoring stack safely with zero data loss.
sudo dnf install -y wget curl git vim tar
sudo dnf install -y grafana
sudo useradd --no-create-home --shell /bin/false prometheus
# Prometheus data
tar -czf prometheus-data.tar.gz /var/lib/prometheus
# Grafana SQLite DB
cp /var/lib/grafana/grafana.db ~/grafana.db.backup
mysqldump -u root -p grafana > grafana.sql
pg_dump -U grafana grafana > grafana.pgsql
scp prometheus-data.tar.gz root@newhost:/tmp/
scp grafana.db.backup root@newhost:/tmp/
scp grafana.sql root@newhost:/tmp/ # If using MySQL
scp grafana.pgsql root@newhost:/tmp/ # If using PostgreSQL
cd /opt
wget https://github.com/prometheus/prometheus/releases/latest/download/prometheus-*.linux-amd64.tar.gz
tar -xzf prometheus-*.tar.gz
mv prometheus-*/ prometheus/
mkdir -p /etc/prometheus /var/lib/prometheus
cp /opt/prometheus/prometheus.yml /etc/prometheus/
useradd --no-create-home --shell /bin/false prometheus
tar -xzf /tmp/prometheus-data.tar.gz -C /
chown -R prometheus:prometheus /etc/prometheus /var/lib/prometheus /opt/prometheus
- job_name: 'node_exporter'
static_configs:
- targets: ['new-server-name:9100']
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
ExecStart=/opt/prometheus/prometheus \
--config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/var/lib/prometheus
[Install]
WantedBy=multi-user.target
systemctl daemon-reexec
systemctl daemon-reload
systemctl enable --now prometheus
sudo dnf install -y grafana
cp /tmp/grafana.db.backup /var/lib/grafana/grafana.db
chown grafana:grafana /var/lib/grafana/grafana.db
mysql -u root -p grafana < /tmp/grafana.sql
psql -U grafana -d grafana < /tmp/grafana.pgsql
systemctl enable --now grafana-server
chown -R prometheus:prometheus /etc/prometheus /var/lib/prometheus /opt/prometheus
chown -R grafana:grafana /var/lib/grafana
http://<ip>:9090http://<ip>:3000This guide helps you migrate your Prometheus and Grafana stack with zero data loss and full operational continuity. From storage to systemd, it aligns with upstream best practices and sets you up for future scalability.
Last updated: August 2025