Open main menu

Changes

448 bytes added ,  12:05, 11 December 2014
improved file naming
== Backup ==
<code>cat ./backup.db.sh</code>
<source lang="bash">
#!/bin/sh
 
DB=wiki
backupdir="$HOME/backups";
fi
backup="$backupdir/dump-$(date +%F).$(hostname)-$DB.sql";
# increment the filename if it already exists
# http://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html#Shell-Parameter-Expansion
i=1
filename=$(basename "$backup") # foo.txt
extension=${filename##*.} # .txt
file=${filename%.*} # foo
while [ -f $backup ]; do
backup="$backupdir/${file}.${i}.${extension}"
i=$(( i+1 )) # increments $i
done
/usr/bin/mysqldump $DB > $backup;
ls -al $backup;
 
</source>
[[Category:Database]]
[[Category:Bash]]
4,558

edits