Sponsored Content
Top Forums Programming Open Source Backup Wordpress with Shell Script Post 302938577 by wyclef on Tuesday 17th of March 2015 07:12:49 PM
Old 03-17-2015
ah, that makes sense!

Trying out a different script here:

How come if I use the following script and select b at the prompt:

Code:
#!/bin/bash
#@author        MagePsycho <magepsycho@gmail.com>
#@website        http://www.magepsycho.com
#@blog            http://www.blog.magepsycho.com
#@version        0.1.0

#/************************ EDIT VARIABLES ************************/
projectName=project_demo
backupDir=/home/user/_backups
#/************************ //EDIT VARIABLES **********************/

fileName=$projectName-$(date +"%Y-%m-%d")
host=$(grep DB_HOST "wp-config.php" |cut -d "'" -f 4)
username=$(grep DB_USER "wp-config.php" | cut -d "'" -f 4)
password=$(grep DB_PASSWORD "wp-config.php" | cut -d "'" -f 4)
dbName=$(grep DB_NAME "wp-config.php" |cut -d "'" -f 4)

printf "What kind of backup you would like?\n[ d ] DB backup only\n[ f ] Files backup only\n[ b ] Files backup with DB\n"
read backupType
if [[ $backupType = @(d|b) ]]; then
    echo "----------------------------------------------------"
    echo "Dumping MySQL..."
    mysqldump -h "$host" -u "$username" -p"$password" "$dbName" | gzip > $fileName.sql.gz
    echo "Done!"
fi

if [[ $backupType = @(f|b) ]]; then
    echo "----------------------------------------------------"
    echo "Archiving Files..."
    tar -zcf $fileName.tar.gz * .htaccess
    echo "Done!"
    echo "----------------------------------------------------"
    echo "Cleaning..."
    rm -f $fileName.sql.gz
    echo "Done!"
fi

if [[ $backupType = @(d|f|b) ]]; then
    echo "----------------------------------------------------"
    mkdir -p $backupDir;
    echo "Moving file to backup dir..."
    if [[ $backupType == d ]]; then
        mv $fileName.sql.gz $backupDir
    fi

    if [[ $backupType = @(f|b) ]]; then
        mv $fileName.tar.gz $backupDir
    fi
    echo "Done!"
else
    echo "Invalid selection!"
fi

it works...

but then if I try to remove all the options and just have it run b I get the following error:

mv: cannot stat `project_demo-2015-03-17.sql.gz': No such file or directory

Code:
#!/bin/bash

#/************************ EDIT VARIABLES ************************/
projectName=project_demo
backupDir=/home/user/_backups
#/************************ //EDIT VARIABLES **********************/

fileName=$projectName-$(date +"%Y-%m-%d")
host=$(grep DB_HOST "wp-config.php" |cut -d "'" -f 4)
username=$(grep DB_USER "wp-config.php" | cut -d "'" -f 4)
password=$(grep DB_PASSWORD "wp-config.php" | cut -d "'" -f 4)
dbName=$(grep DB_NAME "wp-config.php" |cut -d "'" -f 4)

echo "----------------------------------------------------"
echo "Dumping MySQL..."
mysqldump -h "$host" -u "$username" -p"$password" "$dbName" | gzip > $fileName.sql.gz
echo "Done!"

echo "----------------------------------------------------"
echo "Archiving Files..."
tar -zcf $fileName.tar.gz * .htaccess
echo "Done!"
echo "----------------------------------------------------"
echo "Cleaning..."
rm -f $fileName.sql.gz
echo "Done!"

echo "----------------------------------------------------"
mkdir -p $backupDir;
echo "Moving file to backup dir..."
mv $fileName.sql.gz $backupDir
mv $fileName.tar.gz $backupDir
echo "Done!"


Last edited by wyclef; 03-18-2015 at 03:38 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Help with a backup shell script

I'm having an issue with a problem A problem with this backup script is that if you backup the same file twice, you may get a warning message because you're overwriting an existing file. You could suppress the warning message, but a better solution is to save a series of backups distinguished by... (1 Reply)
Discussion started by: Dingosatemypant
1 Replies

2. Shell Programming and Scripting

Need help with a backup shell script

am writing my very first shell script and need some assistance. What I need help on is three things in particular. 1) Do I need to use the sleep function after the tar command or does the script know to wait until tar finishes to move on to the next line? 2) Did I populate the variable DATE... (4 Replies)
Discussion started by: rhm54
4 Replies

3. Shell Programming and Scripting

Help with backup shell script

Hello all, I am trying to backup my system database and root filesystem on remote server that is mounted on my system using tar command. For the database, i use (cd /database; tar cvf file.tar .) for the Root filesystem, i use (cd /; tar uEvf file.tar .) both are to be backup on the same... (1 Reply)
Discussion started by: Omoniyi
1 Replies

4. Shell Programming and Scripting

Help with Backup Shell Script

Hi, I am a linux newbie and I dont have any knowledge on scripting but this is my urgent requirement. I am suppose to write a backup script for 2 of my servers, could someone help me out please. below is my requirement Mail Server 1 : 10.0.0.1 Mail Server 2 : 10.0.0.2 Backup Server... (6 Replies)
Discussion started by: harry289
6 Replies

5. Shell Programming and Scripting

shell script to backup

Q: script to daily backup all databases in the server, retain only last 4 backps please anyone give me a reply (3 Replies)
Discussion started by: pssooraj72
3 Replies

6. Shell Programming and Scripting

Help with Backup Shell Script for Network Device Configuration backup

HI all, im new to shell scripting. need your guidence for my script. i wrote one script and is attached here Im explaining the requirement of script. AIM: Shell script to run automatically as per scheduled and backup few network devices configurations. Script will contain a set of commands... (4 Replies)
Discussion started by: saichand1985
4 Replies

7. Shell Programming and Scripting

Help with Backup Shell Script

i need to print the first date of the previous month in 20130101 format. i use the below script month_year=$(date +'%m%Y' | awk '!--$1{$1=12;$2--}') m=${month_year% *} y=$month_year##* } d=$(cal $m $y | paste -s - | awk '{print $NF}') firstdate=${printf '02d01%s' $y $m) echo $firstdate ... (1 Reply)
Discussion started by: vino1989
1 Replies

8. Shell Programming and Scripting

Shell script to call Oracle archive backup script when file system reaches threshold value

Hello All, I need immediate help in creating shell script to call archivebkup.ksh script when archive file system capacity reaches threshold value or 60% Need to identify the unique file system that reaches threshold value. ex: capacity ... (4 Replies)
Discussion started by: sasikanthdba
4 Replies

9. Shell Programming and Scripting

Help with Backup Shell Script

Dear friends, I need your help. I need to create a bash script which can loop through $source_dir once a month, and find the backup of the last day of a given month for each of the 2 file types, as can be seen below. Assume that source_dir="/backup/daily" Assume that... (1 Reply)
Discussion started by: joemb
1 Replies

10. UNIX for Beginners Questions & Answers

Help with Backup Shell Script

hello guys i am new and i am using Solaris 8 as operating system. i have some CD and i want to install the data from it. Package and patches. Which command shall i use? thanks (3 Replies)
Discussion started by: moh_abaloo
3 Replies
All times are GMT -4. The time now is 08:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy