none
Create batch file to use with scheduler for mysqldump backup file that includes date & time in name. RRS feed

  • Question

  • Hello to all,

    Windows 10 Pro - Mysql version 5.5 - Sam Broadcaster Pro - 2014.5

    As the title states, I have created a batch file through searching the net and trial & error. It works manually but wish to do backups automatically using Scheduler, at first during importing of "tracks" every few hours. Once importing of music is complete, I will switch to once a week or so. My trouble now is to get Power shell to add the date & time to the file  name mainly to have multiple instances of the file for piece of mind. Everything I can find online is for older version of Power shell and returns "errcode 13" - I have also seen errcode 22 many times as well during my trial and error attempts of solving this myself.

    Below is what I have so far of said batch file:

    @ECHO OFF
    "C:\Program Files\MySQL\MySQL Server 5.5\bin\" mysqldump -u root -p'password!' -h localhost samdb --result-file="C:\Users\shann\AppData\Local\SpacialAudio\SAMBC\MySqlBackup\backup.sql"

    I have tried all of the choices I have found online including (get-date) - $gte - (get-item filename).lastwritetime - just to name a few with no success.

    Any suggestions as to what I might be missing in the batch file, as well as the ability to have the date Y time included in the backup file name, is greatly appreciated. :D

    Thank you, in advance, for any and all suggestions.

    Sincerely,

    Shannon Marissa 

    • Moved by jrv Friday, June 29, 2018 9:30 AM correct forum
    Friday, June 29, 2018 9:10 AM

Answers

  • The "workaround" would be to redesign your script as a PowerShell script.

    You can execute PowerShell scripts using Task Scheduler.

    Command: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

    Parameters: -NoProfile -ExecutionPolicy Bypass -File "C:\Script Path\scriptname.ps1" parameter [...]

    Start in: <set as needed>

    (As an aside: It is very, very bad practice to "hard-code" a password in plain-text in a script.)


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by Shannons69 Saturday, June 30, 2018 3:38 AM
    Friday, June 29, 2018 4:56 PM
    Moderator

All replies

  • You cannot use PowerShell commands in a batch file.


    \_(ツ)_/

    Friday, June 29, 2018 9:32 AM
  • That must be why Scheduler doesn't work then as the backup in Mysqldump needs admin privileges and scheduler does not seem to even be able to execute the operation correctly.

    Any workarounds you can think of?

    Shannon Marissa

    Friday, June 29, 2018 2:51 PM
  • The "workaround" would be to redesign your script as a PowerShell script.

    You can execute PowerShell scripts using Task Scheduler.

    Command: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

    Parameters: -NoProfile -ExecutionPolicy Bypass -File "C:\Script Path\scriptname.ps1" parameter [...]

    Start in: <set as needed>

    (As an aside: It is very, very bad practice to "hard-code" a password in plain-text in a script.)


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by Shannons69 Saturday, June 30, 2018 3:38 AM
    Friday, June 29, 2018 4:56 PM
    Moderator
  • That is EXACTLY what I wanted to hear Mr. Stewart,

    An answer that will work! ;) I have no issue what so ever starting fresh to solve this the correct way. I will get right to work on learning how. Thank you ever so much, I seriously appreciate you taking the time to help a newbie, such as myself to PowerShell. 

    Rather than all of my trial and error, I should have asked first but my stubbornest kept me thinking that there had to be a way. It does get me into trouble at times.

    As for the hard coded password. I would not EVEN think about it if this database had any sensitive idatain it. It only holds my music files for SAM Broadcaster so that I may play my music for myself to enjoy and a very small (For now) internet station I DJ for. I honestly would not even have added it if was not for the fact that I need to use PowerShell in admin mode, which Mysqldump requires to function. ;)  

    Thanks again,

    Shannon Marissa

    P.S. Sorry to JRV, I had no idea that I was posting in the wrong place. Did not see any specific 'board' it should be on. (Guess I didn't look hard enough.) A BIG thank you as well, for moving it to the proper place. ;)

    Saturday, June 30, 2018 4:06 AM