How to Backup MYSQL Databases

REM Export all databases names to file
mysql -h your-server-ip -u user-name -ppassword information_schema --skip-column-names --execute="SHOW DATABASES;" > databases.tmp
echo "Start!"
REM Look over database names

REM Outter loop to get table names

for /F %%A in (databases.tmp) do (
   echo "Exporting table Names for %%A"
   mysql -h your-server-ip -u user-name -ppassword %%A --skip-column-names --execute="SHOW TABLES;" >"%%A_tables.tmp"

   mkdir %%A


#### nested loop to create table name files per table
   for /F %%B in (%%A_tables.tmp) do (
   echo "Exporting data for %%B of %%A"
   mysqldump -h your-server-ip -u user-name -ppassword %%A %%B> "%%A\%%A_%%B.sql"
   )
)

del *.tmp

 

How to Backup Microsoft SQL Server (MSSQL) Databases

--1. Variable declaration

DECLARE @path VARCHAR(500)
DECLARE @name VARCHAR(500)
DECLARE @filename VARCHAR(256)
 
-- 2. Setting the backup path

SET @path = 'X:\MSSQLDB\Backup\'  

DECLARE db_cursor CURSOR FOR  
SELECT name 
FROM master.dbo.sysdatabases 
WHERE name NOT IN ('master','model','msdb','tempdb')  -- ignore system databases

--3. Initializing cursor operations

OPEN db_cursor   
FETCH NEXT FROM db_cursor INTO @name   

WHILE @@FETCH_STATUS = 0   
BEGIN

  -- 4. Defining the filename
    SET @fileName = @path + @name + '.BAK'  
    BACKUP DATABASE @name TO DISK = @fileName 

    FETCH NEXT FROM db_cursor INTO @name   
END   
CLOSE db_cursor   
DEALLOCATE db_cursor