InfluxDB: restore: DB metadata not changed. database may already exist - influxdb

I'm trying to restore DB "test" and started by doing a drop test which was successful, however when I try to restore using influxd restore -portable -newdb "test" test_backup.influx I get this error:
restore: DB metadata not changed. database may already exist
The database is not listed when I show databases so I find this a bit strange.

you can try adding -db , -datadir and -metadir ..
influxd restore -portable -db "test" -newdb "test" -datadir /.../data -metadir /.../meta test_backup.influx

Related

influx: merging large database with select into fails. Alternatives?

influxdb 1.8.10
I have 2 databases which was originally one, but due to hardware limitations,I had to move to a new system and just started a new database there.
now i've upgraded to a new system and wants to merge these two again.
I've restored the backups of both into a seperate docker instance in two db. energypre2021 and energycombined(which has the data beyond 2021)
if I use
influx -database=energycombined -execute 'SELECT * INTO energypre2021..:MEASUREMENT FROM /.*/ GROUP BY *'
in the docker container, i just get kicked out of the docker instance without any messages and no merged db.
the log just says this
ts=2022-09-08T22:30:10.118858Z lvl=info msg="Open store (end)" log_id=0cooRaaG000 service=store trace_id=0cooRa~0000 op_name=tsdb_open op_event=end op_elapsed=4042.491ms
any tips on how to effectively merge both db's? I am willing to merge one table at a time if needed.
influxdb 1.8.10
64GBRam +1TB SSD should be enough power for this stuff me thinks.
I actually did an export -portable of both instances
influxd backup -portable -database energy /mnt/backup/pre2020
influxd backup -portable -database energy /mnt/backup/newestdata
then I restore the instance with the least data (newestdata) in one empty influx instance. . influxd restore -portable -database energy /mnt/backup/newestdata and export a copy of this influx_inspect export -datadir /var/lib/influxdb/data/ -waldir /var/lib/influxdb/wal/ -out /mnt/backup/newestdata.gz
then i drop that instance and restore the export with the most data influxd restore -portable -database energy /mnt/backup/pre2020
and then import the export
influx -import -compressed=true -path=/mnt/backup/newestdata.gz
then I import both instances-backups one by one in one empty influx instance.
You could probably export the database from the two instances separately and then import them one by one.
Step 1: export the database from the two instances
influx_inspect export -compress -datadir /var/lib/influxdb/data -waldir /var/lib/influxdb/wal -out /root/1.gz
influx_inspect export -compress -datadir /var/lib/influxdb/data -waldir /var/lib/influxdb/wal -out /root/2.gz
Step 2: and then you can import these two files one by one:
influx -import -compressed=true -path=/root/1.gz
influx -import -compressed=true -path=/root/2.gz
See more details here on the export and there on the import.

InfluxDB: Move only one database of many from one server instance to another

I have an InfluxDB server instance containing several databases, like sensors, network, telegraf and so on.
Together these databases consume several dozens of GB, and I want to offload only the sensors database to another more powerful machine.
The simplest case would be that I create a new InfluxDB server instance on that other machine, and just move (rsync) the influxdb/data/sensors folder to the other machine, and delete it from the original one.
While I haven't tested it, I assume that this does not work that easily; there is a data/_internal directory, then there's the meta/meta.db file as well as the wal/* directory, which will probably require everything to be left "as-is" in order for the server instance to boot without error.
Since I'm talking about dozens of GBs per database, I'd ideally just would like to mount a new ssd, copy the files/directories, and then mount that new ssd on the other machine and use it directly as the new data source without further copying.
I'd basically wish I could do this in a way as easy as moving rrd-tool's rrd files from one machine to another.
Is this possible? If not, what are my options?
Edit 2022: This is a solution which works for InfluxDB 1.x, the commands shown here may not be directly applicable to 2.x. Here is a link to the 2.x backup/restore documentation: https://docs.influxdata.com/influxdb/v2.2/backup-restore/
The InfluxDB 2.2 influx backup command is not compatible with versions of InfluxDB prior to 2.0.0.
I resorted to using influxd backup / influxd restore as Yuri Lachin pointed out.
While it does have the drawback of first needing to save the data on disc and then read it in from there, it seems to be the the most flexible approach.
Rsyncing 50GB does take a certain amount, and the databases would need to be offline during that time, which is not a requirement for backup / restore; so no data is lost. It also allows to migrate the data which used to be on one single InfluxDB instance to different InfluxDB servers without having to think about the issue with the metadata database.
The backup / restore can be done in steps, where the first step ist to initially backup all the data of the database, restore it into the new server instance, and then exporting the newest data again which didn't make it into the first backup, restoring it again into the new database.
Step 1:
On the machine containing the new, empty InfluxDB server instance, backup the data from the remote, old InfluxDB instance:
influxd backup \
-portable \
-host 192.168.11.10:8088 \
-database sensors \
/var/lib/influxdb/export-sensors-01
Afterwards import this data into the new server instance:
influxd restore \
-portable \
/var/lib/influxdb/export-sensors-01
Step 2:
Now take the time to adjust the IP-address or domain name to which the InfluxDB clients are currently connected, and make them point to the new InfluxDB server; restart the clients if necessary.
Step 3:
During the time the backup finished and you restarted the clients with the new IP-address, new data was still written to the old database, so we will need to sync that data over.
Again, on the new server, pull a backup from the old one, but specify the time range of the missing data and a different target directory:
influxd backup \
-portable \
-host 192.168.11.10:8088 \
-database sensors \
-start 2019-06-22T19:30:00Z \
-end 2019-06-24T00:00:00Z \
/var/lib/influxdb/export-sensors-02
Apparently it is important to specify -end as well, one test I did which had no -end argument started to backup the entire database again. I just ctrl-d'd out of it and deleted /var/lib/influxdb/export-sensors-02 and started it again with the -end argument set.
The -start argument can contain a couple of minutes of the data which already got restored, since during restoring this second backup these duplicated entries will be ignored or overwrite the already existing identical values.
For example, if you start the main backup at 4pm and it finishes at 6pm, the second backup can contain a -start argument of 5:55pm and an -end argument a couple of days in the future, which is no problem, because as soon as you switch the IP-addresses of the client, no more future data will be written to the old database. Probably the -since argument would have been better, but I was experimenting a bit with time ranges so I left it at using -start+-end.
In order to insert the missing data which you just backed up into /var/lib/influxdb/export-sensors-02 you need to do a bit more work, since you can't restore into an already existing database. If you try to do it, nothing is damaged, only a warning message is shown and restore gets aborted.
So we will need to restore the data into a new, temporary database:
influxd restore \
-portable \
-database sensors \
-newdb sensors_tmp_backup \
/var/lib/influxdb/export-sensors-02
Then copy the data into the sensors database:
influx \
-database=sensors_tmp_backup \
-execute 'SELECT * INTO sensors..:MEASUREMENT FROM /.*/ GROUP BY *'
And delete the temporary database:
influx \
-database=sensors_tmp_backup \
-execute 'DROP DATABASE sensors_tmp_backup'
If all is OK, delete the backup directories
rm -rf /var/lib/influxdb/export-sensors-01
rm -rf /var/lib/influxdb/export-sensors-02
Before changing the addresses with Step 2, you can test Step 3 a couple of times, by making the new db catch up the old, current one via a couple of backups. It's a good way to get acquainted with the procedure in Step 3.
If you're running InfluxDB in Docker, like I am doing, you can execute all the commands from the host. Step 3 would then look like this:
docker exec -w /var/lib/influxdb/ influxdb-1.7.6 influxd backup -portable -host 192.168.11.10:8088 -database sensors -start 2019-06-22T19:40:00Z -end 2019-06-24T00:00:00Z /var/lib/influxdb/export-sensors-02
docker exec -w /var/lib/influxdb/ influxdb-1.7.6 influxd restore -portable -database sensors -newdb sensors_tmp_back /var/lib/influxdb/export-sensors-02
docker exec -w /var/lib/influxdb/ influxdb-1.7.6 influx -database=sensors_tmp_back -execute 'SELECT * INTO sensors..:MEASUREMENT FROM /.*/ GROUP BY *'
docker exec -w /var/lib/influxdb/ influxdb-1.7.6 influx -database=sensors_tmp_back -execute 'DROP DATABASE sensors_tmp_back'
docker exec -w /var/lib/influxdb/ influxdb-1.7.6 rm -rf /var/lib/influxdb/export-sensors-01
docker exec -w /var/lib/influxdb/ influxdb-1.7.6 rm -rf /var/lib/influxdb/export-sensors-02
If you are having problems accessing the remote InfluxDB server keep in mind that the RPC-port 8088 is usually bound to localhost for security reasons, so you may need to bind it to 0.0.0.0 first, probably by setting the environment variable INFLUXDB_BIND_ADDRESS on the remote instance to 0.0.0.0:8088, as specified in the documentation, and then restarting the server.
Not sure it is safe to rsync influxdb/data/sensors directory files from a running influxdb instance. At least you should copy files with rsync and a running influxd, then stop influxd service and repeat rsync to fetch recently updated files.
Without copying `influxdb/meta/meta.db' to a new server your new instance won't know about existing old databases and measurements.
AFAIK, the procedure of manual file copying is not officially documented or recommended by InfluxData.
Probably using official influxd backup / influxd restore commands is a safer approach. They were buggy 1-2 years ago when I tried them, but are likely to work now. You can run backup on a new server from remote old instance and restore backup locally.
I may try as you mentioned in your question copy influxdb/data/sensors directory to the new machine.
_internal database maintains the run time statistics. So you can ignore that if you are not looking into that database.
I am ignorant where it is using its metadata, so be cautious.
wal/* - directory is nothing but write ahead log to avoid data loss. I assume you have some downtime for this activity. If you can find most recent data within sensor DB before you do this copying, there is not chance for data loss from wal.

Hyperledger Explorer

I have installed all prerequisites for setting up the hyperledger Explorer but when I start it, I got the following error in log file:
And my config.json file is this:
Postgres' command also done:
1: https://i.stack.imgur.com/eTpSY.png
2: https://i.stack.imgur.com/IocQU.png
You're database setup is not done correctly, run these commands one by one.
Database setup
Connect to PostgreSQL database
sudo -u postgres psql
Run create database script
\i app/db/explorerpg.sql
\i app/db/updatepg.sql
Run db status commands.
\l view created fabricexplorer database
\d view created tables
Actually it postgres database error ...
In your error its clearly said that the chaincode_id doesnt exit ... so this is the problem .
if you want check what column are existed in the transaction table just follow below step
cd blockchain-explorer/app/persistence/postgreSQL/db
sudo -u postgres psql
\d transactions
check the corresponding column chaincode_id exist or not (it wont exist now ,Thats why you got this error)....
Solution for this type error
If you got any error like this first just go to the blockchain-explorer/app/persistence/postgreSQL/db directory
There you can see two file explorerpg.sql and updatepg.sql open this two file and check the corresponding column if existed on any of this file or not. If not you better to download explorer another version which contain the corresponding columns either of this two file mentioned above.
if existed just run below command on ubuntu
cd blockchain-explorer/app/persistence/postgreSQL/db
sudo -u postgres psql
\i explorerpg.sql
\i updatepg.sql
Once done this command just check the column "chaincode_id " is created or not by
\d transactions
it will list all column just check it on.
if the chaincode_id is exist run the explorer again ....

I need to restore db from dump and cannot do it

I have a database dump at D:/backup.dump. I try to restore my database min_ro: I open psql.exe plugin. There are words
min_ro=#
Then I write restore command:
min_ro=# psql min_ro < D:/backup.dump
Then happens nothing. My database is not restored. What is wrong? It's first time using psql.
Update. I don't need psql only - I need to restore db from dump and cannot do it.
psql is not a SQL statement, so it doesn't make sense to enter that at the psql prompt which is there to run SQL statements (or psql meta commands).
c:\> psql min_ro < D:/backup.dump
needs to be entered on the (Windows) command line, not inside psql.
You can however just run the SQL script (which I assume your dump is) by using the \i ("include") meta command in `psql``
c:\> psql min_ro
min_ro=# \i D:/backup.dump
When you restore your database at pgAdminIII (by right-click at database name then choice 'restore') you can't see .dump files at backup list by default. That was my mistake forced me to try another ways to restore DB from dump.
But if you simply change file types to 'All files' you can restore your database from dump as usially.

Backup neo4j community edition offline in unix: mac or linux

Previously I had a problem when making a 'backup' as shown in this question where I get an error when trying to restore the database because I did a copy when the database was running.
So I did an experiment with a new database from another computer (this time with ubuntu) I tried this:
I created some nodes and relations, very few like 10 (the matrix example).
Then I stopped the service neo4j
I copied the folder data that contains graph.db to another location
After that I deleted the graph.db folder and started neo4j
It created automatically a new graph.db folder and the database runs as new without any data, that is normal.
Then I stopped again and paste the old graph.db folder
I get an error:
Starting Neo4j Server...WARNING: not changing user waiting
for server to be ready... Failed to start within 120 seconds.
The error appears after 5 seconds not after 120 seconds.
I tried pasting the folder called data. Same error.
How should I backup and restore in neo4j community offline manually?
I read in some posts that you only copy and restore but that does not work.
Thank you for your help
Online backup, in a sense of taking a consistent backup while Neo4j is running, is only available in Neo4j enterprise edition. Enterprise edition's backup also features a verbose consistency check of the backup, something you do not get in community either.
The only safe option in community edition is to shutdown Neo4j cleanly and copy away the graph.db folder recursively. I'm typically using:
cd data
tar -zcf graph.db.tar.gz graph.db/
For restoring you shut down neo4j, clean out a existing graph.db folder and restore the original graph.db folder from your backup:
cd data
rm -rf graph.db
tar -zxf graph.db.tar.gz
I also ran into this issue and wrote following two codes:
Make backup of momentary state
service neo4j stop && now=$(date +"%m_%d_%Y") && cd /var/lib/neo4j/data/databases/ && tar -cvzf /var/backups/neo4j/$now.gb.tar.gz graph.db && service neo4j start
service neo4j stop = stop the neo4j service
now=$(date +"%m_%d_%Y") = declare the current date as variable
cd /var/lib/neo4j/data/databases/ = change directories to your neo4j dir where the graph.db is located
tar -cvzf /var/backups/neo4j/$now.gb.tar.gz graph.db = make a compressed copy of the graph.db and save it to /var/backups/neo4j/$now.gb.tar.gz
service neo4j start = restart neo4j
Restore neo4j database from a backup
service neo4j stop && cd /var/lib/neo4j/data/databases/ && rm -r graph.db && tar xf /var/backups/neo4j/10_25_2016.gb.tar.gz -C /var/lib/neo4j/data/databases/ && service neo4j start
service neo4j stop = stop the neo4j service
cd /var/lib/neo4j/data/databases/ = change directories to your neo4j dir where the graph.db is located
rm -r graph.db = remove the current graph.db and all its contents
tar xf /var/backups/neo4j/10_25_2016.gb.tar.gz -C /var/lib/neo4j/data/databases/ = Extract the backup to the directory where the old graph.db was located. Be sure to adjust the filename 10_25_2016.gb.tar.gz to what you called your file
service neo4j start = restart neo4j
Info:
This seems to work for me but as I do not have alot of experience with bash scripting I doubt this is the optimal way. But I think it is understandable and easy to customize :)
Cheers
If you cant shutdown and copy the file then you can write a cron script to fetch the data from Neo4j and store it in some other database , say mongodb. You can write cron script to restore also.
This method is only for those who dont have money to buy enterprise edition and cant shutdown his server .

Resources