INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Backup from command line?  (Read 1205 times)

MarkCoutinho

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 676
Backup from command line?
« on: September 20, 2024, 02:34:58 pm »

Hi all,

I just checked the Wiki page of MC, but there seems to be no command for backing up the library.
Is that true or is there a way to do that by command line?
Logged
Mark Coutinho
Dutch Top 40 collector of lyrics, sleeves and bios

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42376
  • Shoes gone again!
Re: Backup from command line?
« Reply #1 on: September 20, 2024, 02:40:32 pm »

You can do it with an MCC.

20011
MCC_BACKUP_LIBRARY,                            // [int nMode (0: normal, 1: silent automatic backup)]
Logged
Matt Ashland, JRiver Media Center

MarkCoutinho

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 676
Re: Backup from command line?
« Reply #2 on: September 21, 2024, 10:21:44 am »

You can do it with an MCC.

20011
MCC_BACKUP_LIBRARY,                            // [int nMode (0: normal, 1: silent automatic backup)]

Thanks for that, Matt.
Just wondering: although I know that I have preset the location of the backup field, I want to add the path to that location in the command. The reason for that is that I back it up to my Google Drive and that location is differnt at home than at my work, if you know what I mean.
So: is it possible to add the backup location to the command?

Thanks.
Logged
Mark Coutinho
Dutch Top 40 collector of lyrics, sleeves and bios

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42376
  • Shoes gone again!
Re: Backup from command line?
« Reply #3 on: September 21, 2024, 04:29:32 pm »

Would it work to simply configure each MC to a different backup folder?  Options > File Location > Program Files > Library backups.

Thanks.
Logged
Matt Ashland, JRiver Media Center

MarkCoutinho

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 676
Re: Backup from command line?
« Reply #4 on: September 22, 2024, 04:21:41 am »

It would if I wouldn't be restoring the settings each time too. Hence why I'm looking for this command line solution.
But if that's isn't possible, I just have to deal with it
Logged
Mark Coutinho
Dutch Top 40 collector of lyrics, sleeves and bios

zeltak

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 494
Re: Backup from command line?
« Reply #5 on: September 22, 2024, 06:49:09 am »

I would also love to have a way to backup and restore via the command line (using MCC commands) as it would make keeping the library "synced" (or at least the same :)) between my main desktop and laptop

thx!

z
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2619
Re: Backup from command line?
« Reply #6 on: September 22, 2024, 12:57:05 pm »

It would if I wouldn't be restoring the settings each time too. Hence why I'm looking for this command line solution.
But if that's isn't possible, I just have to deal with it

You could have a script/bat to issue the MCC command, wait a bit, then copy the backup file to the folder you want.
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42376
  • Shoes gone again!
Re: Backup from command line?
« Reply #7 on: September 22, 2024, 07:06:16 pm »

I'll add a command line function tomorrow.  Thanks for the help :)
Logged
Matt Ashland, JRiver Media Center

MarkCoutinho

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 676
Re: Backup from command line?
« Reply #8 on: September 25, 2024, 05:50:47 am »

I'll add a command line function tomorrow.  Thanks for the help :)
Super!
Logged
Mark Coutinho
Dutch Top 40 collector of lyrics, sleeves and bios

zeltak

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 494
Re: Backup from command line?
« Reply #9 on: September 27, 2024, 06:09:09 pm »

Code: [Select]
3. NEW: Added a /BackupLibrary command line tool (takes a filename for the zip file).
thx matt, is it possible to request a /RestoreLibrary option as well as a command line tool?
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42376
  • Shoes gone again!
Re: Backup from command line?
« Reply #10 on: September 27, 2024, 06:34:33 pm »

I think /RestoreLibrary should already work.  There's also /RestoreLibraryAndSettings and /RestoreSettings.
Logged
Matt Ashland, JRiver Media Center

MarkCoutinho

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 676
Re: Backup from command line?
« Reply #11 on: September 28, 2024, 02:25:57 am »

Wow! That's more than I hoped for!
This is exactly why I'm a fan of MC since version 8 or something: the forum board with the builders in it - direct answers when needed and sometime action when wanted.

Thanks!
Logged
Mark Coutinho
Dutch Top 40 collector of lyrics, sleeves and bios

MarkCoutinho

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 676
Re: Backup from command line?
« Reply #12 on: September 30, 2024, 07:54:22 am »

I'm sorry to bother you: I can't find the explanation of this command line tool in the Wiki.
If I want to backup the library to for instance c:\music\library mediacenter, what would the full command be that can be run from the command line in Windows (and thus in a batch file that I will schedule)
Logged
Mark Coutinho
Dutch Top 40 collector of lyrics, sleeves and bios

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42376
  • Shoes gone again!
Re: Backup from command line?
« Reply #13 on: September 30, 2024, 08:02:56 am »

Just pass the path to a zip file for backup.

MC33.exe /BackupLibrary "C:\Temporary\MC Lib.zip"
Logged
Matt Ashland, JRiver Media Center

MarkCoutinho

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 676
Re: Backup from command line?
« Reply #14 on: October 01, 2024, 06:44:14 am »

Works like a charm.
For those interested: I've made a batch file that first backs up the library to a file. After that it renames the file to the format MC always backs up itself (i.e. MC Library Backup (Main Library - 2024-09-28 09-12).
I use the current date/time to rename the file to.

And that batch file I run every day as a scheduled action as well as at home as at my work. (remind: my backup path at work differs from the path at home - hence this solution)
Logged
Mark Coutinho
Dutch Top 40 collector of lyrics, sleeves and bios

MarkCoutinho

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 676
Re: Backup from command line?
« Reply #15 on: October 01, 2024, 12:01:25 pm »

I think /RestoreLibrary should already work.  There's also /RestoreLibraryAndSettings and /RestoreSettings.

I just tried this:

mc33.exe /RestoreLibraryAndSettings "c:\music\MediaCenter backups\"

but nothing happens.

What should I do differently?
Logged
Mark Coutinho
Dutch Top 40 collector of lyrics, sleeves and bios

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42376
  • Shoes gone again!
Re: Backup from command line?
« Reply #16 on: October 01, 2024, 12:06:13 pm »

I would expect you to need the filename to be a ZIP of the settings and library file.  A folder isn't enough.
Logged
Matt Ashland, JRiver Media Center

MarkCoutinho

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 676
Re: Backup from command line?
« Reply #17 on: October 01, 2024, 12:50:55 pm »

I would expect you to need the filename to be a ZIP of the settings and library file.  A folder isn't enough.
Ah, I see... Than this command tool is no use to me. But I'm super happy with the backup one though!
Logged
Mark Coutinho
Dutch Top 40 collector of lyrics, sleeves and bios

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2619
Re: Backup from command line?
« Reply #18 on: October 01, 2024, 12:54:52 pm »

You just need a script to automatically determine the most recent filename.

Just curious, why would you automate a DB restore?
Logged

zeltak

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 494
Re: Backup from command line?
« Reply #19 on: October 01, 2024, 05:44:06 pm »

Hi zybex!

to "sync" settings across a main laptop and a secondary laptop when on the go :)
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2619
Re: Backup from command line?
« Reply #20 on: October 02, 2024, 03:15:36 am »

This .bat restores the most recent ZIP backup in a given folder:

Code: [Select]
@echo off
if "%1"=="" echo Usage: MCRestoreLatest c:\Backup\Folder\Path & goto :EOF
set folder=%1
set mask=*.zip

FOR /F "eol=| delims=" %%f IN ('DIR "%folder%\%mask%" /A-D /B /O-D /TW 2^>nul') DO SET "newest=%%f" & GOTO FOUND
echo No %mask% file found in %folder%
GOTO :EOF

:FOUND
echo.
echo Newest file is: "%newest%"
echo.
echo Restoring MC Database in 5 seconds, press CTRL+C to cancel
timeout 5

echo.
mc33.exe /RestoreLibraryAndSettings "%folder%\%newest%"
Logged

MarkCoutinho

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 676
Re: Backup from command line?
« Reply #21 on: October 02, 2024, 10:10:05 am »

You just need a script to automatically determine the most recent filename.

Just curious, why would you automate a DB restore?
I use it only to automate the restore process as much as I can by hitting just one (combination of) key(s).
Logged
Mark Coutinho
Dutch Top 40 collector of lyrics, sleeves and bios

MarkCoutinho

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 676
Re: Backup from command line?
« Reply #22 on: October 02, 2024, 10:11:46 am »

I use it only to automate the restore process as much as I can by hitting just one (combination of) key(s).
Super, thanks! I'm not home right now, but I will give your code a go.
Logged
Mark Coutinho
Dutch Top 40 collector of lyrics, sleeves and bios

MarkCoutinho

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 676
Re: Backup from command line?
« Reply #23 on: October 02, 2024, 10:15:53 am »

As Zybex has published the restore batch he made, I feel free to show the backup batch I've made.
This batch backs up the library and then renames it to the way MC by default names its back up files. You just have to adjust your own paths.


@echo off
MC33.exe /BackupLibrary "c:\Users\Mark\Google Drive\MediaCenter backups\MC Library Backup.zip"

:: set pause to wait for the backup process to finish
timeout 10

setlocal

:: Retrieve date and time in the correct format (yyyy-MM-dd HH-mm)
for /f "tokens=2-4 delims=/- " %%a in ('date /t') do (
    set year=%%c
    set month=%%b
    set day=%%a
)

for /f "tokens=1-2 delims=:." %%a in ('time /t') do (
    set hour=%%a
    set minute=%%b
)

:: Convert time to 24-hour format as needed
if %hour% lss 10 set hour=0%hour%

:: Set old file name and path
set "source=c:\Users\Mark\Google Drive\MediaCenter backups\MC Library Backup.zip"
set "path=c:\Users\Mark\Google Drive\MediaCenter backups\"
::set "filename=MC Library Backup %year%-%month%-%day% %hour%-%minute%.zip"
set "filename=MC Library Backup (Main Library - %year%-%month%-%day% %hour%-%minute%).zip"
 
:: Rename file
ren "%source%" "%filename%"

echo File renamed to: %path%%filename%

endlocal
Logged
Mark Coutinho
Dutch Top 40 collector of lyrics, sleeves and bios

MarkCoutinho

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 676
Re: Backup from command line?
« Reply #24 on: October 04, 2024, 02:23:08 am »

I think /RestoreLibrary should already work.  There's also /RestoreLibraryAndSettings and /RestoreSettings.
I've done some extensive testing, but /RestoreLibraryAndSettings and /RestoreSettings both don't restore the settings, so that needs some adjustment.
If I restore the library 'by hand' (with the same zip file) the settings are being restored as expected. But that's not the case with the command
Logged
Mark Coutinho
Dutch Top 40 collector of lyrics, sleeves and bios

zeltak

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 494
Re: Backup from command line?
« Reply #25 on: October 05, 2024, 08:24:19 am »

I think /RestoreLibrary should already work.  There's also /RestoreLibraryAndSettings and /RestoreSettings.

thx so much @Matt, how does it know though which backup (file, location etc) to restore from?

best

z
Logged
Pages: [1]   Go Up