Difference between revisions of "Backup scripts"
Jump to navigation
Jump to search
Rafahsolis (talk | contribs) (Created page with "== Wikimedia == <nowiki> #!/bin/bash FNAME=`date +%Y-%m-%d` mysqldump --database DATABASE_NAME -u USERNAME -pPASSWORD --add-drop-table -B > ${FNAME}.sql zip -r ./backup/${FNA...") |
Rafahsolis (talk | contribs) |
||
| Line 1: | Line 1: | ||
| − | == Wikimedia == | + | === Wikimedia === |
<nowiki> | <nowiki> | ||
#!/bin/bash | #!/bin/bash | ||
| Line 6: | Line 6: | ||
zip -r ./backup/${FNAME}.zip images/ ${FNAME}.sql LocalSettings.php extensions/ | zip -r ./backup/${FNAME}.zip images/ ${FNAME}.sql LocalSettings.php extensions/ | ||
rm ${FNAME}.sql | rm ${FNAME}.sql | ||
| + | </nowiki> | ||
| + | Bonus (not required): | ||
| + | <nowiki> | ||
| + | # 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 | ||
</nowiki> | </nowiki> | ||
Revision as of 04:00, 22 March 2015
Wikimedia
#!/bin/bash
FNAME=`date +%Y-%m-%d`
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