Skip to content

Instantly share code, notes, and snippets.

@canonex
canonex / siteurlExtractor.sh
Last active July 25, 2022 16:51
Wordpress dump siteurl extractor
#!/bin/bash
#If working from a dump
DB=mydb.sql
grep -F "'siteurl'," "$DB" | head -c 200 | sed 's/, /,/g' | sed 's/^.*\(siteurl.*\)/\1/g' | sed "s/'/ /g" | egrep -o 'https?://[^ ]+' | head -1
#If working in a wordpress env with wp-cli
#wp db query "SELECT option_value FROM $(wp config get table_prefix)options WHERE option_name='siteurl'" --skip-column-names
@canonex
canonex / flockRsyncBackup.sh
Created June 30, 2022 14:39
Rsync and a lock file: flock
#!/bin/bash
# Example of flock use with rsync where local files are pushed to a remote server using a ssh and a key.
# Using flock is useful when file copying is slow and the transfer duration may overlap with a newly scheduled run.
# For example, if a large number of files are uploaded in one day in an office, whose backup is scheduled every day, and the transfer may take more than 24 hours.
# Flock use a lock file: if it already exist it does not execute the command (-n option)
# Read more on https://www.man7.org/linux/man-pages/man1/flock.1.html
flock -n rsyncExec.lock -c 'rsync -aAXH --info=progress2 --delete --delete-excluded -e "ssh -p 12345 -i /myuser/.ssh/mykey" /myrepo/mydata/ myuser@mydomain.net:/mybackup/myfolder/'