InfluxDB : Backup and Restore2022/10/27 |
This is how to back up and restore InfluxDB database.
|
|
[1] | Back up a database. |
# backup [test_database] to [/home/influxd_backup] root@dlp:~# influxd backup -database test_database /home/influxd_backup 2022/10/27 13:50:44 backing up metastore to /home/influxd_backup/meta.00 2022/10/27 13:50:44 backing up db=test_database 2022/10/27 13:50:44 backing up db=test_database rp=autogen shard=6 to /home/influxd_backup/test_database.autogen.00006.00 since 0001-01-01T00:00:00Z 2022/10/27 13:50:44 backing up db=test_database rp=one_day shard=8 to /home/influxd_backup/test_database.one_day.00008.00 since 0001-01-01T00:00:00Z 2022/10/27 13:50:44 backup complete: 2022/10/27 13:50:44 /home/influxd_backup/home/influxd_backup/meta.00 2022/10/27 13:50:44 /home/influxd_backup/home/influxd_backup/test_database.autogen.00006.00 2022/10/27 13:50:44 /home/influxd_backup/home/influxd_backup/test_database.one_day.00008.00root@dlp:~# ll /home/influxd_backup total 20 drwx------ 2 root root 4096 Oct 27 13:50 ./ drwxr-xr-x 4 root root 4096 Oct 27 13:50 ../ -rw-r--r-- 1 root root 607 Oct 27 13:50 meta.00 -rw-r--r-- 1 root root 2048 Oct 27 13:50 test_database.autogen.00006.00 -rw-r--r-- 1 root root 2048 Oct 27 13:50 test_database.one_day.00008.00 # possible to backup specific retention policy or retention duration like follows root@dlp:~# influxd backup -database test_database -retention one_day -since 2022-10-25T00:00:00Z /home/influxd_backup |
[2] | Restore a Backup database. |
# run restore command # [-metadir] : target directory meta data is restored (follow is the default location) # [-datadir] : target directory database is restored (follow is the default location) # [-database] : target database name restored root@dlp:~# influxd restore -metadir /var/lib/influxdb/meta -datadir /var/lib/influxdb/data -database test_database /home/influxd_backup Using metastore snapshot: /home/influxd_backup/meta.00 2022/10/27 14:17:41 Restoring offline from backup /home/influxd_backup/test_database.*
root@dlp:~#
chown -R influxdb:influxdb /var/lib/influxdb/{meta,data} root@dlp:~# systemctl start influxdb
# verify resotored data root@dlp:~# influx -username admin -password adminpassword -database test_database -precision rfc3339 -execute 'select * from weather' name: weather time location temperature ---- -------- ----------- 2022-10-27T04:40:41.629041887Z hiroshima 20 2022-10-27T04:40:44.765376882Z hiroshima 22 2022-10-27T04:40:48.16616743Z osaka 18 2022-10-27T04:40:51.958496424Z osaka 19 |
Sponsored Link |