Sign in to follow this  
Followers 0
<Z>SneakyDude

WIP Simple Backup Scripts -w/mysql

11 posts in this topic

FOR GAWD SAKES READ, and make your own Batchfiles, dont be a dum ass and run my personal scripts... If you dont know how to use batchfiles dont mess around here. Go away.

 

Here is one i use, that does very well. V1.0

It Xcopies C:\Arma stored server (directory) all files *.* then copies the files to your backup Location

it passes arguments /e/h/k/y/z

/e : Copies all subdirectories, even if they are empty. Use /e with the /s and /t command-line options.

/h : Copies files with hidden and system file attributes. By default, xcopy does not copy hidden or system files.

/k : Copies files and retains the read-only attribute on destination files if present on the source files. By default, xcopy removes the read-only attribute.

/y : Suppresses prompting to confirm that you want to overwrite an existing destination file.

/z : Copies over a network in restartable mode.

For more arguments visit:

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/xcopy.mspx?mfr=true

Or google it for other great sites.

Windows based.

ECHO OFF
CLS
color b1
ECHO.
ECHO ...............................................
ECHO ...............................................
ECHO .........SCHEDULED TASK BACKUP.................
ECHO ...............................................
ECHO ...............................................
XCOPY "c:\Arma3Servers\Server3\*.*" C:\Arma3Servers\Backup\Server3\ /e/h/k/Y/z

Change your settings to your own Server Directory, and Backup Drive file locations.

Create a task Scheduler, and link it to this bat file which can be stored in your server root folder.

http://windows.microsoft.com/en-US/windows/schedule-task#1TC=windows-7

You can modify this,  and backups with no flaws i have noticed yet.

** Working on adding in the Mysql Simple backup included in this.**

Sneaks

Edited by <Z>SneakyDude
Modify your Directories you wish backedup

Share this post


Link to post
Share on other sites

Here is a great script to backup files, and Mysql 7-zip backup.

I placed the Batch file into the Backup directory, set to read only, and shortcut it here, then do a task in windows.

1. Install 7-zip if you haven't already. (opens these .sql.gz files)

2. Change all locations to your own.

3. Setup a Windows Task Scheduler or do manual ones.

Modify it to your liking. I am going to work on zipping those Arma  backups in a second. and Date, Time.

ECHO OFF
CLS
color a1
ECHO ...............................................
ECHO .........SCHEDULED TASK BACKUP.................
ECHO ...............................................
XCOPY "c:\Arma3Servers\Server4\*.*" C:\Arma3Servers\Backup\Server4\ /e/h/k/Y/z
XCOPY "c:\Arma3Servers\Server3\*.*" C:\Arma3Servers\Backup\Server3\ /e/h/k/Y/z
ECHO .....Done With Server Backups......
@echo off

 set dbUser=root
 set dbPassword=***put your root password here.***
 set backupDir="C:\Arma3Servers\Backup\MySQLBAK\"
 set mysqldump="C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqldump.exe"
 set mysqlDataDir="C:\ProgramData\MySQL\MySQL Server 5.6\data\"
 set zip="c:\Arma3Servers\Backup\zip\7za.exe"

 :: get the current date
 for /F "tokens=2-4 delims=/ " %%i in ('date /t') do (
      set yy=%%i
      set mon=%%j
      set dd=%%k
 )

 :: get the current time
 for /F "tokens=5-8 delims=:. " %%i in ('echo.^| time ^| find "current" ') do (
      set hh=%%i
      set min=%%j
 )

 echo dirName=%yy%%mon%%dd%_%hh%%min%
 set dirName=%yy%%mon%%dd%_%hh%%min%
 
 :: switch to the "data" folder
 pushd %mysqlDataDir%

 :: iterate over the folder structure in the "data" folder to get the databases
 for /d %%f in (*) do (

 if not exist %backupDir%\%dirName%\ (
      mkdir %backupDir%\%dirName%
 )

 %mysqldump% --host="localhost" --user=%dbUser% --password=%dbPassword% --single-

transaction --add-drop-table --databases %%f > %backupDir%\%dirName%\%%f.sql

 %zip% a -tgzip %backupDir%\%dirName%\%%f.sql.gz %backupDir%\%dirName%\%%f.sql

 del %backupDir%\%dirName%\%%f.sql
 )
 popd

Edited by <Z>SneakyDude

Share this post


Link to post
Share on other sites
Advertisement

Here is a complete package i have done for 2 servers, both running Exile, one is my stable .19 server, and the other is the .20 server Experimental.

 

You need to make a folder inside your backup called

zip

http://downloads.sourceforge.net/sevenzip/7za920.zip

extract those to that folder so it can compress the files.

Its a tad sloppy, since its just in a revised state to backup my stuff only.  Remove the 2nd server stuff as it may not be needed for you.

What it does

1. Copies data from the Server folder

2. Compresses the files, calling it S4backup.zip (xcopy does not have a compress)

3. Renames the S4backup.zip to (todays date)server4.zip

4. Does the same for the next server folder.

5. does the mysql backups

6. goes to the end and starts deleting the files it doesn't need. Fresh Server3 folder, fresh Server4 folder, no S3-S4backup.zip files

but has a 50% ratio compressed file approx. and your left with mysql folders by time, date stamped.

** I will rework this as i go** for now it works for 2 servers, all you have to do is rename your file/folder locations and then give it a test. It does not touch active servers files or folders. It only copies them to another location. Seems to be ok, while servers online, no lag reported.

Version 2.0

ECHO OFF
CLS
color f1
ECHO ............................................
ECHO ............................................
ECHO ............................................
::SCHEDULED TASK BACKUP Server 4
XCOPY "c:\Arma3Servers\Server4\*.*" C:\Arma3Servers\Backup\Server4\ /e/h/k/Y/z

::Now Zipping Server 4
set zip="C:\Arma3Servers\Backup\zip\7za.exe"
C:\Arma3Servers\Backup\zip\7za a -tzip C:\Arma3Servers\Backup\S4backup.zip "c:

\Arma3Servers\Backup\Server4\"

::Now Renaming Server 4
rename "C:\Arma3Servers\Backup\S4backup.zip" %Date:~-10,2%_%Date:~-7,2%_%Date:~-

4,4%Server4.zip

ECHO ............................................
ECHO ............................................
ECHO ............................................

::SCHEDULED TASK BACKUP Server 3
XCOPY "c:\Arma3Servers\Server3\*.*" C:\Arma3Servers\Backup\Server3\ /e/h/k/Y/z

::Now Zipping Server 3
set zip="C:\Arma3Servers\Backup\zip\7za.exe"
C:\Arma3Servers\Backup\zip\7za a -tzip C:\Arma3Servers\Backup\S3backup.zip "c:

\Arma3Servers\Backup\Server3\"

::Now Renaming Server 3
rename "C:\Arma3Servers\Backup\S3backup.zip" %Date:~-10,2%_%Date:~-7,2%_%Date:~-

4,4%Server3.zip


ECHO ............................................
ECHO ............................................
ECHO ............................................

::Lets Backup MySQL, Set Paths Now
 set dbUser=root
 set dbPassword=
 set backupDir="C:\Arma3Servers\Backup\"
 set mysqldump="C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqldump.exe"
 set mysqlDataDir="C:\ProgramData\MySQL\MySQL Server 5.6\data\"
 set zip="C:\Program Files\7-zip\7z.exe"

 :: get the current date
 for /F "tokens=2-4 delims=/ " %%i in ('date /t') do (
      set yy=%%i
      set mon=%%j
      set dd=%%k
 )

 :: get the current time
 for /F "tokens=5-8 delims=:. " %%i in ('echo.^| time ^| find "current" ') do (
      set hh=%%i
      set min=%%j
 )

 echo dirName=%yy%%mon%%dd%_%hh%%min%
 set dirName=%yy%%mon%%dd%_%hh%%min%
 
 :: switch to the "data" folder
 pushd %mysqlDataDir%

 :: iterate over the folder structure in the "data" folder to get the databases
 for /d %%f in (*) do (

 if not exist %backupDir%\%dirName%\ (
      mkdir %backupDir%\%dirName%
 )

 %mysqldump% --host="localhost" --user=%dbUser% --password=%dbPassword% --single-

transaction --add-drop-table --databases %%f > %backupDir%\%dirName%\%%f.sql

 %zip% a -tgzip %backupDir%\%dirName%\%%f.sql.gz %backupDir%\%dirName%\%%f.sql

 del %backupDir%\%dirName%\%%f.sql
 )
 popd

ECHO ............................................
ECHO ............................................
ECHO ............................................
ECHO ............................................
ECHO ............................................
ECHO ............For ADVANCED USERS ONLY.  It deletes the 2 sever directories in Backup, and 2 non renamed files s3 and S4 Zip files. Leaving you with 09_20_2015Server3.zip and 09_20_2015Server4.zip and 09202015_1443.zip for the mysql

::Done With Server Backups, Now delete files...
Del "C:\Arma3Servers\Backup\S3backup.zip"
Del "C:\Arma3Servers\Backup\S4backup.zip"
set folder="c:\Arma3Servers\Backup\Server4\"
cd /d %folder%
for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q)

set folder="c:\Arma3Servers\Backup\Server3\"
cd /d %folder%
for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q)

Edited by <Z>SneakyDude

Share this post


Link to post
Share on other sites

I take no credit for the code in mysql, or the compress, i googled bits and pieces to understand how it worked. Its all piece work from snippets of code.

enjoy!

Share this post


Link to post
Share on other sites

So for the lazy people

ECHO OFF
CLS
color f1
ECHO ............................................
ECHO ............................................
ECHO ............................................
::SCHEDULED TASK BACKUP Server 4
XCOPY "c:\Arma3Servers\Server4\*.*" C:\Arma3Servers\Backup\Server4\ /e/h/k/Y/z

::Now Zipping Server 4
set zip="C:\Arma3Servers\Backup\zip\7za.exe"
C:\Arma3Servers\Backup\zip\7za a -tzip C:\Arma3Servers\Backup\S4backup.zip "c:

\Arma3Servers\Backup\Server4\"

::Now Renaming Server 4
rename "C:\Arma3Servers\Backup\S4backup.zip" %Date:~-10,2%_%Date:~-7,2%_%Date:~-

4,4%Server4.zip

ECHO ............................................
ECHO ............................................
ECHO ............................................

    ::Lets Backup MySQL, Set Paths Now

 set dbUser=root
 set dbPassword=
 set backupDir="C:\Arma3Servers\Backup\"
 set mysqldump="C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqldump.exe"
 set mysqlDataDir="C:\ProgramData\MySQL\MySQL Server 5.6\data\"
 set zip="C:\Program Files\7-zip\7z.exe"

 :: get the current date
 for /F "tokens=2-4 delims=/ " %%i in ('date /t') do (
      set yy=%%i
      set mon=%%j
      set dd=%%k
 )

 :: get the current time
 for /F "tokens=5-8 delims=:. " %%i in ('echo.^| time ^| find "current" ') do (
      set hh=%%i
      set min=%%j
 )

 echo dirName=%yy%%mon%%dd%_%hh%%min%
 set dirName=%yy%%mon%%dd%_%hh%%min%
 
 :: switch to the "data" folder
 pushd %mysqlDataDir%

 :: iterate over the folder structure in the "data" folder to get the databases
 for /d %%f in (*) do (

 if not exist %backupDir%\%dirName%\ (
      mkdir %backupDir%\%dirName%
 )

 %mysqldump% --host="localhost" --user=%dbUser% --password=%dbPassword% --single-

transaction --add-drop-table --databases %%f > %backupDir%\%dirName%\%%f.sql

 %zip% a -tgzip %backupDir%\%dirName%\%%f.sql.gz %backupDir%\%dirName%\%%f.sql

 del %backupDir%\%dirName%\%%f.sql
 )
 popd

ECHO ............................................
ECHO ............................................
ECHO ............................................
ECHO ............................................
ECHO ............................................
ECHO ............................................

Make sure you set up your own Delete script, i take no responsibility for deletions. It will leave 2 zip files, and 2 backup of arma server.

You can manually delete that or go from the delete script and modify it to your own.

Edited by <Z>SneakyDude
removed final part. due to dangers without reading on batchfiles
1 person likes this

Share this post


Link to post
Share on other sites

It is deleting the files from my desktop. Any ideas why? 

XCOPY "c:\Arma3Servers\Server4\*.*" C:\Arma3Servers\Backup\Server4\ /e/h/k/Y/z

this copies from c: to c: you must change it to your server and your Backup location.

09_20_2015Server3.zip and 09_20_2015Server4.zip

and 09202015_1443.zip for the mysql

the sql is setup

 set backupDir="C:\Arma3Servers\Backup\"
 set mysqldump="C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqldump.exe"
 set mysqlDataDir="C:\ProgramData\MySQL\MySQL Server 5.6\data\"
 set zip="C:\Program Files\7-zip\7z.exe"

so i must tell it where the backup drive is located, and the mysql version you have. Also its important to get 7zip using 7z.exe for the command prompt.

I do have the file for the 7z.exe i can upload it to our site if people need this.

Seems to be working  very well on my small server, i have tons of backups. I use c:\ because its a simple server, i recommend you having a different backup location, or you can also copy the 09_20_2015Server4.zip again to that location,.

All you need to do is put in

XCOPY "c:\Your server location\*.*" F:\your backup directory\ /e/h/k/Y/z

What did you put into these fields? nothing calls for the desktop to be deleted.

Share this post


Link to post
Share on other sites

It is deleting the files from my desktop. Any ideas why? 

::Done With Server Backups, Now delete files...
Del "C:\Arma3Servers\Backup\S4backup.zip"
set folder="c:\Arma3Servers\Backup\Server4\"

 

This is set to delete the old backup created Del "C:\Arma3Servers\Backup\S4backup.zip" and leaves the new one 09_20_2015Server4.zip

So you don't have too many files left over.

set folder="c:\Arma3Servers\Backup\Server3\"
cd /d %folder%
for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q)

 

This sets the folder to server3 and deletes all the files left over. Backup\Server3 as you can see above.

Also did you put the program into the Backup Directory.? This is the location i have, and make a shortcut to the desktop for manual backups. I made a task scheduled for it and it does it automatically.

Edited by <Z>SneakyDude

Share this post


Link to post
Share on other sites

4 Screen Images with directory structure i have just for emergency server backups in case i need to go backwards and retrieve files.

screen1.jpg

screen2.jpg

screen3.jpg

screen4.jpg

Share this post


Link to post
Share on other sites
Advertisement

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.