Jump to content

[Release] MySQL DB backup v1.1.


Recommended Posts

MySQL DB backup v1.1.

 

Note: This script is included in the DayZEpoch 1.0.6 distribution (when released).

 

Possible future improvements.

 

 

Hey Rimblock! Great work producing this- I have been thinking about some kind of automated backup system for some time! :)

 

It's a bit of a departure from what you've done here, but I was wondering if you liked the idea of using database events to make the backup to the database itself instead of, or as well as to a file? ie. event just copies the tables to backup_tablename_date within the same database or similar?

Link to comment
Share on other sites

i did not see one for linux here, so i thought i would share this i made:

#enter db username here
DBUSER=myuser
#enter db password here
DBPASS=mypass
#enter path where you want your backups to go
DBBACKUPDIR=/path/where/backups/will/end
#end user settings
DBDIR=$DBBACKUPDIR/$(date +'%A')
DBFILE=${1}_$(date +%Y_%d-%m_%H.%M-%S).sql
DBNAMEINDIR=$DBDIR/$DBFILE

if [ -d $DBDIR ];then
	echo "Dir $DBDIR already exists"
else
	echo "Creating Dir $DBDIR"
	mkdir -p "$DBDIR"
fi

echo "Backing up Database To File $DBDIR/$DBFILE ..."

mysqldump --user=$DBUSER --password=$DBPASS $1 > $DBNAMEINDIR

#showing old db's
			#-mmin = +minutes
#find ${DBBACKUPDIR} -type f -mmin +240
			#-mtime = +days
#find ${DBBACKUPDIR} -type f -mtime +2

#deleting older than 3days db's
find $DBBACKUPDIR -type f -mtime +3 -delete

edit user name, pass, path and save it to a file named something like dbbackup.sh then execute like this:

./dbbackup.sh mydbname
Link to comment
Share on other sites

  • 7 months later...

I have tried this but it's not working.  It makes an SQL file with a file size of zero.   The connection name is mikes, Im not sure if that is what the mysql user name should be or not.  My MySQLWorkbench.exe is installed in this path  C:\FTP\MySQL Workbench 6.3.4 CE (win32).  I put the mysqldir different because in the path above did not have the MYSQL Server 5.7\bin directory in it.  In my hive.ini the database password is blank thats why I did not enter anything in that spot. 

Here is my bat file.

@REM *** PARAMETERS/VARIABLES ***
SET BackupDir="C:\FTP\Server Backup"
SET mysqldir="C:\Program Files\MySQL\MySQL Server 5.7\bin"
SET mysqlschema=dayz_epoch
SET mysqlpassword=[Enter database password]
SET mysqluser=mikes
SET housekeepafter=5

for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' SET ldt=%%j
set datestamp=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2%.%ldt:~8,2%-%ldt:~10,2%-%ldt:~12,2%

@REM *** EXECUTION ***@REM Change to mysqldir
c:
cd %mysqldir%

@REM dump/backup ALL database, this is all in one line
mysqldump -u %mysqluser% -p%mysqlpassword% --databases %mysqlschema% --routines --events --triggers --quick >%BackupDir%\%mysqlschema%_backup.%datestamp%.sql

@REM - Housekeeping
forfiles -p %BackupDir% -s -m *.sql -d -%housekeepafter% -c "cmd /c del @path"

 

Someone on the first page had the same problem.  They were told to add read at the end.  I tried that and it showed more stuff in the command but it closed in 2 seconds or so, so I could not read it.  I then added pause under read so I could see what it said.  Screenshot of the CMD box

http://i950.photobucket.com/albums/ad343/n612ua/backup batch_zpszndn52gg.png

If someone would please let me know what I did wrong that would be great.

 

Thanks

Link to comment
Share on other sites

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
×
×
  • Create New...