MySql and SQL Server backup with code - c++

I try to back up from MySQL with codes. Is it possible?
If it will possible, I could use this code getting backup from SQL Server.
Thank a lot.

The easiest way is to use the command-line tool mysqldump.
mysqldump -u username -ppassword -h hostname databasename > filename.sql
It can create dumps from local or remote databases.
It is a part of the mySQL installation package (in the /bin directory)

Related

How to transfer one mongodb database from one computer to another

I am using django 2.2 and mongodb as database for backend. i have inserted all data in my application.I am also using Robo3T for seeing collections of mongodb database.My database name is CIS_FYP_db. In my computer everything is going perfect but i want to transfer that project into another computer while i am transferring the project which also contains data\db file with many collections.wt files but when i am running that project in other computer it is showing me that database is blank.No data were present there and mongodb is making new database with the same name CIS_FYP_db with no collections.Please help me to solve this problem that how can i transfer my mongodb database into other computer so i can use it into my application which is already made for that database.Thanks in advance
setting.py
DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'CIS_FYP_db',
}
}
When you create a connection with mongodb then database is created automatically if not exist already.
You can use mongodump command to get all the database records and mongorestore to restore your database on your new machine.
Assumption: you have setup mongoDb locally and want to migrate it to another computer.
1.Requirements:
mongodump
mongorestore
1.1.How to install?
to install above requirement u have to install [MongoDB Database
Tools]
download link: https://www.mongodb.com/try/download/database-tools
1.2.Popular error.
sometime path is not set, so try this in cmd prompt: set path="C:\Program Files\MongoDB\Server\5.0\bin"
Note: please refactor the link according to your folder path.
2.Procedure:
Note: make sure you follow Step 1
2.1. Approach
we are going to create dump of mongodb from old pc(using mongodump), then transfer that dump to new pc, and import that dump using mongorestore.
2.2.Creation of dump in old pc(from where u want to replicate database)
cmd mongodump --host localhost:27017 --out ~/Desktop/mongo-migration
above cmd will create a dump in the mentioned path==> ~/Desktop/mongo-migration
just copy that folder and transfer it to new pc
Note: if you have created authenticated user then add these flag in above cmd and provide values --username [yourUserName] --password [yourPassword] --authenticationDatabase admin
2.3.Import of dump(created from old PC)
place that dump folder somewhere and execute below cmd
mongorestore C:/....../mongo-migration/ -u root --host 127.0.0.1:27017
done :)

Unable to restore sql file in postgresql on windows

I'm trying to import sql file in postgresql but unable to do. I tried pgAdmin 4 to restore sql file. I get the error (pg_restore: [archiver] input file does not appear to be a valid archive).
I've also tried to do this with the command prompt but unable to do.
If I do
D:\Program Files (x86)\PostgreSQL\9.1\bin>psql -h 127.0.0.1 -U postgres gorkha < D:/gorkha.sql
It returns
SET
SET
SET
SET
SET
CREATE EXTENSION
COMMENT
REVOKE
REVOKE
GRANT
GRANT
Create a DB like (Employees)
Lets say you have a employees.sql file which you want to restore
postgres is your username
AT command prompt you are in the same folder with employees.sql
Code sample is:
psql -U postgres -d Employees < employees.sql
Follow This Steps:
Open pgAdmin and open Servers -> PostgreSQL 14 -> Databases,
And Choose your DB and right click and click on the PSQL Tool
If you not set your binary path and you get this alert
and click File option in top of pgadmin & open preference
Click The file icon and set the following path and Save
Final Step Open your Sql File in VSCode or note pad and copy then paste it on the PSQL Tool in pgAdmin
Its Work For Me
If any Error and Convert SQL To PGSQL (more online tools are available)
and the copy paste in to PSQL Tool in pgAdmin
use this command to restore an archived backup using pg_restore
pg_restore -U <username> -d <dbname> -1 <filename>.sql
for text/sql based backup you can try
psql -U <username> -d <dbname> -1 -f <filename>.sql

InfluxDB Cannot see databases from localhost:8083 + Cannot access Command Line Interface

Please feel free to redirect me to any other place if this isn't the right one for this question.
Problem: When I log to the administration panel : "localhost:8083" with "root" "root" I cannot see the existing databases nor the data in it. Also, I have no way to access InfluxDB from the command line.
Also the line sudo /etc/init.d/influxdb start does not work for my setup. I have to go into /etc/init.d/ and run sudo ./influxdb start -config=config.toml in order to get the server running.
I've installed influxDB v0.8 from https://influxdb.com/docs/v0.8/introduction/installation.html for Ubuntu 14.04.
I've been developing a Clojure program using the Capacitor API just to get started and interact with InfluxDB. It runs well, I can create delete, insert and query a database without problems.
netstat -anp | grep LISTEN confirms me that ports 8083 8086 8090 and 8099 are listening.
I've been Googling all around but cannot manage to get a solution.
Thanks for the support and enjoy building things !
Problem solved: the database weren't visible in firefox but everything is visible in Chromium!
Why couldn't I access the CLI ? I was expecting the v0.8 to behave exactly like the v0.9.
You help was appreciated anyway !
For InfluxDB 0.9 the CLI could be started with:
/opt/influxdb/influx
then you can display available databases:
Connected to http://localhost:8086 version 0.9.1
InfluxDB shell 0.9.1
> show databases
name: databases
---------------
name
collectd
graphite
> use collectd
Using database collectd
> show series limit 5
You can try creating new database from CLI:
> CREATE DATABASE mydb
or with curl command:
curl -G 'http://localhost:8086/query' --data-urlencode "q=CREATE DATABASE mydb"
Web UI should be available on http://localhost:8083

Exporting .csv data locally from a distant MySQL server

I have a MySQL server running on one PC (WinXP).
On another PC (WinXP), I'd like to backup tables to csv files so I have a c++ program connect to the MySQL database and then I issue a command like this:
SELECT data FROM table WHERE something=ABC
INTO OUTFILE c\tmp.txt
FIELDS TERMINATED BY ';'
OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY ";";
the data seems to get exported but on the Servers "c:\" not on my PC:s "c:\".
I can't just fetch the data over the LAN either as my program is running as a windows service.
I have seen this post but it seems I can't use "FIELDS TERMINATED BY" etc. with that solution.
Can I export csv data locally from a distant server or do I have to migrate the data locally first?
Problem "solved" : As it seems you can't do it in a 'simple' way, I run the service on the PC with MySQL and have a DCom server periodically move the data to the other PC.
Intended to be a comment (but I don't have enough rep points to comment). Not sure if you are able to install things, but you could try using cygwin + sqsh (http://www.sqsh.org/sqsh_home.html). I'm a linux user and sqsh is a great tool for grabbing data from databases.
SELECT ... INTO OUTFILE obviously writes the file on the local filesystem of the mysql-demon. One option might be to share a directory of your client-PC, open it on your server and use its path for the outfile-option. If this is not an option you might have to select the data in your c++ program and write it (kind of manually) to a local csv-file.
use the following command, if you don't want to install extra.
mysql -h remotedb.db -u ident -p -B -e "your query ;" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > localfile.csv
-B means make the output as tab separated.

Bitnami Redmine backup strategy

We started using Redmine at work. I know it uses MySQL as the database, and Apache 2 as the web server. How can Redmine be properly backed up so that it can be reloaded quickly when anything goes wrong?
This will do just fine:
mysqldump --single-transaction --user=user_name --password=your_password redmine_database > backup.sql
It will dump the entire contents of the redmine_database to the backup.sql file.
Update:
As far as backing up "apache", as I state in my comment below - you don't need or want to back up your apache installation. If you ever need to recover your system, apache would need to be reinstalled as with any other application. If you are referring to the actual files and directories within your redmine installation, those as well don't need to be backed up except for the files/ directory which contains user uploaded files to redmine. You can backup your entire redmine installation (to be safe) with the following command:
tar czvf redmine_backup.tar.gz /path/too/redmine/installation
Run it as a VM (JumpBox has a quickstartable one, I believe) then periodically pause or shutdown the VM and backup/copy the entire virtual disk.
I know this doesn't help with an existing installation, but it's what I'd recommend to anyone planning backups before they implement. That's not meant to be snide, just helpful to anyone else reading this thread.
Bitnami apps are self contained, so another option if you can afford some downtime, is simply to shutdown the server, and zip the directory contents ... You may want to do this maybe once a week, in addition to your mysqldump backups. This way you also capture any changes that may have happened in Apache, etc.
Read the Redmine user guide (look at the bottom).
Also, don't forget to backup the attached files.
Redmine backups should include:
Data (stored in your redmine database)
attachments (stored in the files directory of your Redmine install)
Here is a simple shell script that can be used for daily backups (assuming you're using a MySQL database):
# Database
/usr/bin/mysqldump -u <username> -p<password> <redmine_database> | gzip > /path/to/backup/db/redmine_`date +%y_%m_%d`.gz
# Attachments
rsync -a /path/to/redmine/files /path/to/backup/files
Redmine sets table charset as "latin1".
So, if you use non-latin1 charset (CJK in UTF-8 or something), you should give following option to backup script.
mysqldump -u root -p --default-character-set=latin1 --skip-set-charset bitnami_redmine -r backup.sql
It skips "set charset blah-blah-blah" on sql dump and you would get a clean(=dump without interpretation) dump.
By the way, you have to back up the files directory as well; it holds all uploaded files. I installed the Bitnami Redmine stack on Windows.
For MySQL, I use MySQLAdmin to schedule database backup every day.
And I use aceBackup to automatic backup database dump files and Redmine uploaded files to a remote FTP server.
When the server is something wrong, I can just reinstall the Bitnami Redmine stack, and import early dumped database file, then cover Redmine's files directory with backup files.
And that's OK.
This separate program (Bitnami Redmine stack) and data (database & uploaded files) perfectly.