Backup
Make sure prometheus is running with the flag
$ curl http://<prometheus-url>:9090/api/v1/status/flags | jq .data | grep web.enable-admin-apiIf not edit the prometheus server entrypoint and add this flag --web.enable-admin-api.
Then take a snapshot
$ curl -X POST http://<prometheus-url>:9090/api/v1/admin/tsdb/snapshotThen under prometheus data path defined using --storage.tsdb.path usually it’s under /var/lib/prometheus, You will file a directory named snapshots
root@prometheus:/var/lib/prometheus# ll snapshots/total 8drwxr-xr-x  2 prometheus prometheus 4096 Aug 25 21:13 ./drwxr-xr-x 54 prometheus prometheus 4096 Aug 27 07:00 ../Mine is empty but you will find a dirs which are hard links to all data blocks dirs.
Backup the dir as tarball, this can take time so it’s better to executed under a terminal screen.
Before you backup make sure that you have enough space to avoid filling up the machine root fs.
$ tar -zcvf /var/lib/prometheus/snapshots/* prom-bak-.tar.gzSave the prom-bak-.tar.gz to some reliable storage like S3 or to your local NAS servers.
You can save space after you pushed the archive by deleting the snapshots directory, and the archive.
Restore
After archiving and transferring the snapshot to the new prometheus, the restore is simple as :
Stopping prometheus service.
$ systemctl stop prometheusBack up old data dir
$ mv /var/lib/prometheus/* /opt/prom-old-dataExtract the content of snapshot to prometheus data dir
$ tar -zxvf prom-bak.tar.gz -C /var/lib/prometheus/Reload prometheus
$ curl -x POST <prometheus-url>:9090/-/reloadOr restart prometheus service
$ systemctl restart prometheus.service