E
E
Eugene2013-11-25 01:37:26
MySQL
Eugene, 2013-11-25 01:37:26

How to write a script for Power Shell?

There is a cmd script that creates MySQL dumps in the MYSQL_Dumps folder:

@echo off
echo Starting Backup of Mysql Database on server 
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set dt=%%c-%%a-%%b)
For /f "tokens=1-4 delims=:." %%a in ('echo %time%') do (set tm=%%a%%b%%c)
mkdir C:\MYSQL_Dumps
forfiles /p C:\MYSQL_Dumps\ /s /m *.* /d -0 /c "cmd /c del @file"
echo ===============================================================
set bkupfilename=<database_name>_%dt%.%tm%.sql
"C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqldump.exe" --routines -u <username> -<password> -h <host> --port=<port> <database_name> > C:\MYSQL_Dumps\"%bkupfilename%"
echo ===============================================================
echo Backup Complete!

There is also a script for PS that copies files from a folder to FTP:
#we specify the directory where all files that we want to upload  
$Dir="C:/MYSQL_Dumps"   

#ftp server 
$ftp = "ftp://<FTPhost>/MySQL_Dumps/" 
$user = "<FTPuser>" 
$pass = "<FTPpass>"  
 
$webclient = New-Object System.Net.WebClient 
 
$webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)  
 
#list every sql server trace file 
foreach($item in (dir $Dir "*")){ 
    "Uploading $item..." 
    $uri = New-Object System.Uri($ftp+$item.Name) 
    $webclient.UploadFile($uri, $item.FullName) 
 }

Help me write a single script for Power Shell that will:
1 - Create the C:\MySQL_Dumps folder
2 - Create MySQL dumps of the specified databases in C:\MySQL_Dumps
3 - Archive the C:\MySQL_Dumps folder into one file
4 - Send this archive to the FTP folder /MySQL_Dumps
5 - Clean up trash

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question