How to copy file from C to a network folder? - mysql

I want to copy a file in C:\file.txt to a netword drive which unc path is \fic-bleu\MPM-DICIR\SERVICE-TUNNELS\
I see in Google i have to use pushd and popd but it only modify the current prompt. And i can't use the mysqldump command from this new prompt.
I tried :
cd C:\xampp\mysql\bin
pushd \\ficbleu\MPM-DICIR\SERVICE-TUNNELS
mysqldump.exe --opt --user=root --host=localhost service_tunnels > service_tunnels.sql
popd \\ficbleu\MPM-DICIR\SERVICE-TUNNELS
And
cd C:\xampp\mysql\bin
mysqldump.exe --opt --user=root --host=localhost service_tunnels > pushd \\ficbleu\MPM-DICIR\SERVICE-TUNNELS\service_tunnels.sql
Maybe i have first to save in my computer the dumpsql file and then copy bu i can't find a way to do that :(
Finally i established this script :
#echo off
cd C:\xampp\mysql\bin
mysqldump.exe --opt --user=root --host=localhost service_tunnels > service_tunnels.sql
C:\Windows\System32\xcopy "C:\xampp\mysql\bin\service_tunnels.sql" "\\ficbleu\MPM-DICIR\SERVICE-TUNNELS\01. MAIN COURANTE - MAINTENANCE\Saves\service_tunnels.sql"
Pause
But they said that there are too many arguments so i found a solution in google that says to add quotes to drive path and now its says that is invalid drive path...

Correct answer, need to map network drive as a letter (Y:\ for me)
#echo off
cd C:\xampp\mysql\bin
mysqldump.exe --opt --user=root --host=localhost service_tunnels > service_tunnels.sql
C:\Windows\System32\robocopy "C:\xampp\mysql\bin" "Y:\01. MAIN COURANTE - MAINTENANCE\Saves" *.sql
Pause

Related

Crontab wont work with `mysqldump: command not found` mac osx

I set to cronjob to my local machine
❯ crontab -l
* * * * * ~/.scripts/db_back_up.sh
❯ cat db_back_up.sh
#!/bin/sh
cd /usr/bin/
mysqldump --user=**** --password=**** --host=localhost mydbname > ~/Documents/db_backup/$(date +\%Y_\%m_\%d)_DB_dump.sql 2>&1
But it didn't work. with message - mysqldump: command not found
Look for command path with 'which mysqldump' and add it in your script /path/mysqldump and try again.

Batch file doesn't write the result in the desired directory?

I have the following batch-file on windows-10 which is very close to working with only one small problem.
The .sql result file is written outside of the desired folder. The batch file properly creates the folder and the file, but fails to change into the desired directory when it creates the .sql result file.
For example, it creates D:\Backups\MySQL\MyDatabase__04-27-2018-14-22, and writes the file MyDatabase__04-27-2018-14-22.sql in the MySQL folder, rather than inside the folder with the exact same name.
I've tried variations of changing the directory with no success.
set dt=%date:~-10,2%-%date:~-7,2%-%date:~-4,4%-%time:~0,2%-%time:~3,2%
set dt=%dt: =0%
if exist "D:\Backups\" (mkdir D:\Backups\MySQL\MyDatabase__%dt%
CD ..
CD ..
CD /D D:\Backups\MySQL\MyDatabase__%dt%
START /WAIT C:\xampp\mysql\bin\mysqldump.exe --user=root --password= --host=localhost --port=3306 --result-file="D:\Backups\MySQL\MyDatabase_%dt%.sql" --default-character-set=utf8 --single-transaction=TRUE --databases "MyDatabase"
) else if exist "H:\Backups\" (mkdir H:\Backups\MySQL\MyDatabase__%dt%
CD ..
CD ..
H:
CD H:\Backups\MySQL\MyDatabase__%dt%
START /WAIT C:\xampp\mysql\bin\mysqldump.exe --user=root --password= --host=localhost --port=3306 --result-file="H:\Backups\MySQL\MyDatabase_%dt%.sql" --default-character-set=utf8 --single-transaction=TRUE --databases "MyDatabase"
) else if exist "G:\Backups\" (mkdir G:\Backups\MySQL\MyDatabase__%dt%
CD ..
CD ..
G:
CD G:\Backups\MySQL\MyDatabase__%dt%
START /WAIT C:\xampp\mysql\bin\mysqldump.exe --user=root --password= --host=localhost --port=3306 --result-file="G:\Backups\MySQL\MyDatabase_%dt%.sql" --default-character-set=utf8 --single-transaction=TRUE --databases "MyDatabase"
) else mkdir C:\Users\Scotty\Desktop\Backups\MySQL\MyDatabase__%dt%
CD ..
CD ..
C:
CD C:\Users\Scotty\Desktop\Backups\MySQL\MyDatabase__%dt%
START /WAIT C:\xampp\mysql\bin\mysqldump.exe --user=root --password= --host=localhost --port=3306 --result-file="C:\Backups\MySQL\MyDatabase_%dt%.sql" --default-character-set=utf8 --single-transaction=TRUE --databases "MyDatabase"
CD..
CD..
CD C:\Users\Scotty\Desktop\BackupBatchFiles\
The actual result is that the mysqldump result file is placed outside the directory created with the same name. I am expecting the .sql result file to be written INSIDE the directory that the batch file created with the same name.
Well, all lines with mysqldump.exe specify parameter --result-file with
Backups\MySQL\MyDatabase_%dt%.sql
instead of
Backups\MySQL\MyDatabase_%dt%\MyDatabase_%dt%.sql
I suggest following for the batch file which avoids repetitive code:
#echo off
setlocal EnableExtensions DisableDelayedExpansion
set "DateTime=%date:~-10,2%-%date:~-7,2%-%date:~-4,4%-%time:~0,2%-%time:~3,2%"
set "DateTime=%DateTime: =0%"
set "DoLocalBackup="
for %%I in (D H G) do if exist "%%I:\Backups\" set "BackupFolder=%%I:\Backups\MySQL\MyDatabase__%DateTime%" & goto MakeBackup
echo ERROR: Failed to find network backup drive.
:LocalBackup
set "BackupFolder=%UserProfile%\Desktop\Backups\MySQL\MyDatabase__%DateTime%"
set "DoLocalBackup=1"
:MakeBackup
mkdir "%BackupFolder%" 2>nul
if exist "%BackupFolder%\" (
C:\xampp\mysql\bin\mysqldump.exe --user=root --password= --host=localhost --port=3306 --result-file="%BackupFolder%\MyDatabase_%DateTime%.sql" --default-character-set=utf8 --single-transaction=TRUE --databases "MyDatabase"
) else (
echo ERROR: Failed to create backup folder: "%BackupFolder%"
)
if not defined DoLocalBackup goto LocalBackup
endlocal
CD /D "%UserProfile%\Desktop\BackupBatchFiles\"
This batch file creates a backup in first found backup folder on a network drive and additionally one more backup in a subdirectory of current user's desktop directory.
Another solution is even easier because it just chooses from one of four possible backup locations as the batch file code in question.
#echo off
setlocal EnableExtensions DisableDelayedExpansion
set "DateTime=%date:~-10,2%-%date:~-7,2%-%date:~-4,4%-%time:~0,2%-%time:~3,2%"
set "DateTime=%DateTime: =0%"
for %%I in (D: H: G: "%UserProfile%\Desktop") do if exist "%%~I\Backups\" set "BackupFolder=%%~I\Backups\MySQL\MyDatabase__%DateTime%" & goto MakeBackup
echo ERROR: Failed to find network backup drive or local backup folder.
goto EndBackup
:MakeBackup
mkdir "%BackupFolder%" 2>nul
if exist "%BackupFolder%\" (
C:\xampp\mysql\bin\mysqldump.exe --user=root --password= --host=localhost --port=3306 --result-file="%BackupFolder%\MyDatabase_%DateTime%.sql" --default-character-set=utf8 --single-transaction=TRUE --databases "MyDatabase"
) else (
echo ERROR: Failed to create backup folder: "%BackupFolder%"
)
:EndBackup
endlocal
CD /D "%UserProfile%\Desktop\BackupBatchFiles\"
Here is also a third solution which is similar to second solution, but continues the FOR loop if creation of the backup folder failed on a specified possible backup storage location.
#echo off
setlocal EnableExtensions DisableDelayedExpansion
set "DateTime=%date:~-10,2%-%date:~-7,2%-%date:~-4,4%-%time:~0,2%-%time:~3,2%"
set "DateTime=%DateTime: =0%"
set "BackupFolder=Backups\MySQL\MyDatabase__%DateTime%"
for %%I in (D: H: G: "%UserProfile%\Desktop") do if exist "%%~I\Backups\" (
mkdir "%%~I\%BackupFolder%" 2>nul
if exist "%%~I\%BackupFolder%\" (
C:\xampp\mysql\bin\mysqldump.exe --user=root --password= --host=localhost --port=3306 --result-file="%%~I\%BackupFolder%\MyDatabase_%DateTime%.sql" --default-character-set=utf8 --single-transaction=TRUE --databases "MyDatabase"
goto EndBackup
) else echo ERROR: Failed to create backup folder: "%%~I\%BackupFolder%"
)
echo ERROR: Failed to find any specified backup folder or to create the
echo current date backup folder in one of the backup folders.
:EndBackup
endlocal
CD /D "%UserProfile%\Desktop\BackupBatchFiles\"
Further I would suggest to change the third line to:
set "DateTime=%date:~-4,4%-%date:~-7,2%-%date:~-10,2%-%time:~0,2%-%time:~3,2%"
This results in international date format yyyy-MM-dd which is better than dd-MM-yyyy because of directories/files sorted alphabetically are at the same time sorted chronological using international date format.
Note: The date/time format used for date/time strings of referenced environment variables DATE and TIME as used in third line depends on which country/region is configured for the account which is used running this batch file. See for example Why does %date% produce a different result in batch file executed as scheduled task? for a region independent solution to get current date/time in a specified format.
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
cd /?
echo /?
endlocal /?
for /?
goto /?
if /?
mkdir /? or md /?
set /?
setlocal /?

ExecWait and MySQL with Parameters Not Working

If I run this from a command prompt it works:
C:\Program Files\MariaDB 5.5\bin>MySQL.exe -u root -p --password=xyz --port=3322 --protocol=TCP < "C:\temp folder\CREATE_database.sql"
So I know the .sql script is fine.
But in my NSIS script I see a command prompt window pop up but disappear quickly and the database isn't created:
ExecWait '"C:\Program Files\MariaDB 5.5\bin\mysql.exe" -u root -p --password=root --port=3322 --protocol=TCP < "C:\temp folder\CREATE_database.sql"'
Am I not passing in the parameters to MySQL.exe properly?
ExecWait just creates a simple process, it does not support stdin/stdout redirection.
You can use cmd.exe as a helper:
Section
nsExec::ExectoStack 'cmd.exe /c if 1==1 "c:\path\to\myapp.exe" -param1 -param2 < "stdin file.txt"'
pop $0
pop $1
DetailPrint "Exit code=$0"
DetailPrint "Output=|$1|"
SectionEnd
or you can use the ExecDos plug-in.

run innobackupex with gzip and pipe display output to file

How is it possible to run this and output the innobackupex output to a file (but still send output to the display)?
innobackupex --user=root --password=pass --databases="db" --stream=tar ./ | gzip -c -1 > /var/backup/backup.tar.gz
I need to ouput the innobackupex log with ... completed OK! in the last line to a file? How can I do that?
I've also noticed that it is a bit challenging to save the "OK" output from xtrabackup to the log file, as the Perl script playing with tty. Here is what worked for me.
If you need execute innobackupex from the command line, you can do:
nohup innobackupex --user=root --password=pass --databases="db" --stream=tar ./ | gzip -c -1 > /var/backup/backup.tar.gz 2>/path/mybkp.log
if you need to script it and get an OK message you can do:
/bin/bash -c "innobackupex --user=root --password=pass --stream=tar ./ | gzip -c -1 > /var/backup/backup.tar.gz" 2>/path/mybkp.log
Please note that in the second command, the double quote closes before the 2>
Prepend
2> >(tee file)
to your command.

Mysql backup error

I wrote the below line to create a mysql backup , for some reasons i'm getting Errcode 13 .
E:\Xampp\xampp\mysql\bin\\mysqldump -u root --add-drop-database -B project_db -r C:\Documents and Settings\Administrator\My Documents\a.sql
Why does the above line fail to execute ? I'm trying to create a DB backup using the above line ? Pls Help
It's probably because file "C:\Documents" does not exist. You probably want this:
-r "C:\Documents and Settings\Administrator\My Documents\a.sql"
^ ^
Try this
E:\Xampp\xampp\mysql\bin\mysqldump -u root --add-drop-database -B project_db > "C:\Documents and Settings\Administrator\My Documents\a.sql"
" " were missing
E:\Xampp\xampp\mysql\bin\mysqldump -u root --add-drop-database -B project_db -r "C:\Documents and Settings\Administrator\My Documents\a.sql"
above command may work