I tried to dump a mysql database with calling a wsh jscript file, but it doesn't work.
I have this code, called with git shell, and it works perfectly:
# If something fails, exit with status other than 0
set -e
# select dump directory
cd "$(git rev-parse --show-toplevel)"
# first, remove our original schema
rm -f "WebShop\DataBase\backup.sql"
# generate a new schema
exec "C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqldump.exe" --skip-comments -u root --password=root webshopdb |sed 's$),($),\n($g' > "WebShop\DataBase\backup.sql"
I tried almost the same code in WSH, but it returns only with the header of the dump file, and doesn't creates the file. I do not have a clue what is working wrong, or how to debug the code... :S
var shellObj = WScript.CreateObject('WScript.Shell');
var exec = shellObj.Exec(
'"C:\\Program Files\\MySQL\\MySQL Server 5.5\\bin\\mysqldump.exe"'+
" --skip-comments -u root --password=root webshopdb |sed 's$),($),\\n($g' > " +
'"D:\\creation\\software developer\\projects\\webshop-refactoring-project\\document root\\WebShop\\DataBase\\backup.sql"'
);
WScript.Echo(exec.StdOut.ReadAll());
I tried with bat files and cmd files too, but they cannot handle the space in the pathes.
Can anybody help?
(For me it would be enough to make somehow an executable from the git code, or make the wsh work... The perfect solution would be if I could call the dump from netbeans, but in life nothing is so ideal... :D )
I made it with file association.
I created a git.bat file:
if not exist %1 exit
set bash=C:\Program Files (x86)\Git\bin\bash.exe
"%bash%" --login -i -c "exec "%1""
And associated it to .hook files.
After that I created a test dump.hook file:
#!/bin/sh
cd "D:/creation/software developer/projects/webshop-refactoring-project/document root/WebShop";
cd "$(git rev-parse --show-toplevel)"
rm -f "WebShop/DataBase/backup.sql"
exec "C:/Program Files/MySQL/MySQL Server 5.5/bin/mysqldump.exe" --skip-comments -u root --password=root webshopdb |sed 's$),($),\n($g' > "WebShop/DataBase/backup.sql"
exit
And it works perfectly.
After 3 days I got it! Woohoo! :D
note: *Windows command prompt usually has problems with whitespace and special characters in the path name, so it is much easier to use the emulated linux of git, than try to fix it. It is possible to source the .hook file into a pre-commit git hook too, so it can automatically dump the database schema by every commit... (maybe the git add not working by those files, I haven't found an auto dump and commit solution yet: git pre-commit + mysqldump: cannot find path, not existing command) *
Related
I am new to bash and trying to run the following script on Git Bash for Windows, on Windows Server 2022:
"C:\Program Files\Git\bin\bash.exe" -c C:/Users/agentSvc/AppData/Roaming/Composer/vendor/debricked/cli && php bin\console debricked:scan '' 123 gitHubOrg/repoName 456 https://github.com/repo local
I have falsified some of the values.
The documentation is here:- https://debricked.com/docs/integrations/cli.html
However, I get errors such as "Is a directory", etc. What is the correct syntax here? I am trying to change directory as per the documentation and then run the command.
We would like Teamcity to build our solutions on every commit into subversion.
Following the documentation, we are to create a .sh script :-
SERVER=https://buildserver-url
USER=buildserver-user
PASS="<password>"
LOCATOR=$1
# The following is one-line:
(sleep 10; curl --user $USER:$PASS -X POST "$SERVER/app/rest/vcs-root-instances/commitHookNotification?locator=$LOCATOR" -o /dev/null) >/dev/null 2>&1 <&1 &
exit 0
Subversion is running on a windows environment, and so the .sh file will fail.
We are trying to convert this into a .bat file of which we have :-
set SERVER=https://buildserver-url
set USER=buildserver
set PASS=password
LOCATOR=%1%
(timeout 10; curl --user %USER%:%PASS% -X POST "%SERVER%/app/rest/vcs-root-instances/commitHookNotification?locator=%LOCATOR%" -o /dev/null) >/dev/null 2>%1% <%1% &
exit 0
However, this is still failing when trying to execute with
"The system cannot find the path specified"
It seems that perhaps we havnt converted this correctly?
Are the programs you're referencing (such as curl and timeout.exe) in locations that are present in the $PATH/%PATH% variable? How about any other files you're referencing - are you specifying full paths
Side note: Did you install curl and timeout.exe on the Windows server?
Also, /dev/null does not exist on Windows; you need to redirect to NUL. You can't just change the file extension and some of your syntax and expect a bash script to work on Windows.
Were I in your shoes, I'd skip batch altogether and write the script in something modern and sane like Powershell.
I am using Git Bash, and I would like to write a script that processes the same set of commands for each directory (local repo) in my home directory. This would be easy enough in DOS, which most consider as handicapped at best, so I'm sure there's a way to do it in bash.
For example, some pseudo-code:
ls --directories-in-this-folder -> $repo_list
for each $folder in $repo_list do {
...my commmand set for each repo...
}
Does anyone know how to do this in Bash?
You can do that in bash (even on Windows, if you name your script git-xxx anywhere in your %PATH%)
#! /bin/bash
cd /your/git/repos/dir
for folder in $(ls -1); do
cd /your/git/repos/dir/$folder
# your git command
done
As mentioned in "Git Status Across Multiple Repositories on a Mac", you don't even have to cd into the git repo folder in order to execute a git command:
#! /bin/bash
cd /your/git/repos/dir
for folder in $(ls -1); do
worktree=/your/git/repos/dir/$folder
gitdir=$worktree/.git # for non-bare repos
# your git command
git --git-dir=$gitdir --work-tree=$worktree ...
done
I have a pre-commit hook that's running a mysqldump to keep track of MySQL.
I'm trying to add that dump to the commit, but for some reasons it won't.
The code:
#!/bin/sh
rm -f database.sql
exec "C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqldump.exe" --skip-comments -u root --password=password my-database > database.sql
git add database.sql
The file is created, but not added to the commit.
Running TortoiseGit on Windows 7.
I don't know if it will help you, but here a step by step guide, how it works on my windows 10 machine with xampplite.
go to your project git
go to "hooks\"
create file "pre-commit" (without file ending)
go to file properties and give full access to windows user
open pre-commit and paste:
#!/bin/sh
"C:\xampplite\mysql\bin\mysqldump.exe" -u dbuser -ppassword
database_name > database_name.sql
git add database_name.sql exit 0
(-u username -ppassword databasename > file.sql)
file will be stored in project root. between -p and password is NO space.
Now, before every commit a mysql dump will be done and added to the commit.
In order to use rsync I created a BASH script. It runs fine from the Cygwin shell in WIN 7 but fails when run from the WIN 7 Task Scheduler. My Task Scheduler Script is a simple:
c:\cygwin\bin\bash.exe -l -c "~user/rsync_Windows_Backup 2>&1 >> ~user/Documents_cron.log"
The initial directory is set to C:\Cygwin\bin.
My BASH script is a typical rsync command with [options] SRC DEST and some related housekeeping.
The rsync command within the "rsync_Windows_Backup" BASH script is:
/bin/time -f "\nElapse (hh:mm:ss.ss) %E" \
rsync.exe -v -rltz --chmod=a=rw,Da+x -u "$SRC" "$DEST" >> "$LOG" \
2 >> "$LOG"
$ ./rsync_Windows_Backup - succeeds.
But the Task Scheduler Job fails carping that it cannot find the DEST Folder that the BASH script references. When I do a "cd DEST" from the BASH command line the Folder is avialable and can be written to.
I should add some more details that the sender is a WIN 7 desktop that is mapped to a Vista desktop receiver with a drive mapping J:. The BASH script does start but fails with:
rsync: writefd_unbuffered failed to write 4 bytes to socket [sender]: Broken pipe (32)
rsync: mkdir "/cygdrive/J/DocumentsBackup" failed: No such file or directory (2) rsync error: error in file IO (code 11)
I have tried several ideas to influence how WIN 7 handles mappings and permissions assuming this is the root of the problem. So far nothing seems to help.
Another characteristic is that the exact same BASH script and Task Scheduler Job does succeed it WIN Vista Business Edition. So I am assuming there is something in WIN 7 that I am missing.
I am stumped and could use some guidance.
Thanks.
I now have this working in Win 7 from the task scheduler as I need. Thank you to #netubsi and #firerat of LinuxQuestionsorg and #konsolebox for the suggestions that lead to a solution.
Here is what I did:
cmd /c net use T: '\\server\share' # Created a separate temporary share for Cygwin
DEST="/cygdrive/T/User/FolderBackup/" # Use temporary Share in Destination
rsync -avuz --copy-links "$SRC" "$DEST" # Do backup
cmd /c net use T: /delete # Remove temporary share
It appears that in WIN 7 the share created in Windows is NOT available to a Cygwin script, IF it is launced from the Win 7 task scheduler. It IS available if the script is launced from the Cygwin command line. It also appears that this is NOT an issue in Win Vista.
This seems odd to me. Perhaps there is another explanation that I am missing. However I am just relieved to have this working!!
You can also just use the network address directly in cygwin:
DEST="//server/share/User/FolderBackup"
Cygwin mounts local and mapped drives under /cygdrive. Using taskscheduler in win7 if you list the contents of /cygdrive, all you will see are local drives???
First option is to run your script as
c:\cygwin\bin\bash.exe -l -c "~/rsync_Windows_Backup >> ~/Documents_cron.log 2>&1"
If you want to capture the stderr output as well, you have to place it in front to copy the fd of the file, and not of stdout.
Make sure that rsync_Windows_Backup has executable permissions. Running ls -l ~/rsync_Windows_Backup should show it.
If it doesn't work, try to use absolute paths. On your Cygwin screen where the current direcory shows ~ in the prompt type pwd which would show something like
User#System ~
$ pwd
/home/User
Basing from that as an example your command should now be like:
c:\cygwin\bin\bash.exe -l -c "/home/User/rsync_Windows_Backup >> /home/User/Documents_cron.log 2>&1"