Difference between revisions of "Backup scripts"

From RHS Wiki
Jump to navigation Jump to search
Line 1: Line 1:
 +
= HD dd =
 +
<source lang=bash>#!/bin/bash
 +
 +
# UUID="d3438d58-1a53-470d-934d-fe4cd7aaca06"    /
 +
# dev/sdl1: PARTUUID="2c42328a-01"  grub?
 +
 +
 +
USAGE="./$(basename ${0}) UUID output_filename"
 +
 +
if [ -z "${1}" ]; then
 +
    echo ${USAGE}
 +
    exit
 +
fi
 +
if [ -z "${2}" ]; then
 +
    echo ${USAGE}
 +
    exit
 +
fi
 +
 +
 +
BACKUP_ROOT=/mnt/backup
 +
HD=$(blkid|grep $1|awk -F : '{print $1}')
 +
 +
ISO=${BACKUP_ROOT}/$(hostname)/$(date '+%Y/%m')/$2.iso
 +
 +
echo "dd if=${HD} of=${ISO} bs=1M"
 +
dd if=${HD} of=${ISO} bs=1M</source>
 +
 
= MediaWiki =
 
= MediaWiki =
 
First add the following line to LocalSetings.php
 
First add the following line to LocalSetings.php

Revision as of 19:15, 7 February 2019

HD dd

#!/bin/bash

# UUID="d3438d58-1a53-470d-934d-fe4cd7aaca06"    /
# dev/sdl1: PARTUUID="2c42328a-01"   grub?


USAGE="./$(basename ${0}) UUID output_filename"

if [ -z "${1}" ]; then
    echo ${USAGE}
    exit
fi
if [ -z "${2}" ]; then
    echo ${USAGE}
    exit
fi


BACKUP_ROOT=/mnt/backup
HD=$(blkid|grep $1|awk -F : '{print $1}')

ISO=${BACKUP_ROOT}/$(hostname)/$(date '+%Y/%m')/$2.iso

echo "dd if=${HD} of=${ISO} bs=1M"
dd if=${HD} of=${ISO} bs=1M

MediaWiki

First add the following line to LocalSetings.php

$wgReadOnly = 'Dumping Database, Access will be restored shortly';

Delete this line after the backup.
The script should be in the MediaWiki installation (where your LocalSettings.php is stored as well).

mediawiki_mysql_backup.sh

#!/bin/bash
FNAME=TS=RHSWiki`date +%d-%m-%Y`
mysqldump --database DATABASE_NAME -u USERNAME -pPASSWORD --add-drop-table -B > ${FNAME}.sql
zip -r ./backup/${FNAME}.zip images/ ${FNAME}.sql LocalSettings.php extensions/
rm ${FNAME}.sql

Bonus (not required):

# careful here .. if this fails you'll delete files from the current directory instead.
# Some checking might be in order, especially if you run this script from somewhere else
cd backup
 
#Count files in directory (hidden files (filename starts with a dot) are ignored) 
file_count=`ls | wc -l` 
 
#Do until there are more than or equal 6 files present
while [ $file_count -ge 6 ]
do
        #you can save deleted filenames in variable (e.g. for deleting files also in backup directory)
        #not recommended for filenames with space(s)
        del_files="${del_files} `ls | head -n 1`"
	#Delete alphabetically oldest file (ls sort by name is default)
	rm `ls | head -n 1` 
	#Count files again
	file_count=`ls | wc -l`
done

Source