Bruker:Mihho/db-backup.sh

Fra IThjelp
< Bruker:Mihho
Sideversjon per 8. aug. 2024 kl. 16:46 av Mihho (diskusjon | bidrag) (Ny side: <source lang=bash> #!/bin/bash LISTA=`find /var/lib/mysql/ -maxdepth 1 -type d | awk -F '/' '{print $5}' | sort | uniq | sed '/^$/d'` # Find all databases, make the necessary mysqldump command, save it to a runme.sh file which can be run after for i in $LISTA; do echo "cd /backup/helge; mysqldump --lock-tables=false $i > /backup/helge/$i.$(date +%Y-%m-%d:%T).sql"; done > /backup/helge/runme.sh echo "cd /backup/helge/; gzip *.sql" >> /backup/helge/runme.sh # make it runable chmo…)
(diff) ← Eldre sideversjon | Nåværende sideversjon (diff) | Nyere sideversjon → (diff)
#!/bin/bash

LISTA=`find /var/lib/mysql/ -maxdepth 1 -type d | awk -F '/' '{print $5}' | sort | uniq | sed '/^$/d'`

# Find all databases, make the necessary mysqldump command, save it to a runme.sh file which can be run after
for i in $LISTA; do echo "cd /backup/helge; mysqldump --lock-tables=false $i  > /backup/helge/$i.$(date +%Y-%m-%d:%T).sql"; done > /backup/helge/runme.sh
echo "cd /backup/helge/; gzip *.sql" >> /backup/helge/runme.sh

# make it runable
chmod 755 /backup/helge/runme.sh

# Go backup!
/backup/helge/runme.sh

# Save the commands in the runme.sh file to a local git repo?
cd /backup/helge/
git commit -m "runme.sh: db-backup kommandoene" runme.sh

exit;