Jump to content

[SOLVED] help with shell script


Recommended Posts

ok so I have no idea how to go about building this shell script.

 

I have an external HDD on my web server.  I basically want to make backups of my web root directory and store 90 days worth.  I want to basically write a script to match the following

 

PLATFORM:

UBUNTU 9.04 RUNNING APACHE

 

run everyday..I assume this is a crontab function

 

 

backup directories are named "backup_".a        where a = 1-90

 

figure out how to get the last directory saved to

 

Since I do not want to override my backups if a server boot happens.

I supposed the last directory saved will have to be a check on the date?

 

get $a of last directory saved to

$a++

cp * /var/www /media/Elements/backup_$a

 

 

Link to comment
https://forums.phpfreaks.com/topic/174286-solved-help-with-shell-script/
Share on other sites

Your probably much better of making what's known as an incremental backup. This saves spaces by only backing up data that has changed.

 

Its easily achieved using rsync instead of a plain old copy. If you google rsync incremental backup you should find plenty of example scripts around, its pretty common practice.

If you want to do a full backup you can do something simple like this. Just make it run daily using a cron job.

 

#!/bin/bash

BACKUP_DIR=/path/to/your/backups
SOURCE_DIR=/var/www

mkdir -p $BACKUP_DIR

TIMESTAMP=`date +%Y-%m-%d-%H%M`
tar cfj $SOURCE_DIR/backup_$TIMESTAMP.tar.bz2

find $BACKUP_DIR/* -mtime +7 -exec rm -rf {} \;

doesn't an incremental backup overwrite the changes?  which would be fine as long as I have 90 days worth...if I change a file everyday over 90 days..and the error was in the 28th one..I want to be able to go back and restore that file back to day 28.  I assumed incremental backups overwrite changes so I could not go back to day 28 and restore it from there..I could only restore the last day 89.

ok so the content of my backup script is as follows

 

#!/bin/bash

BACKUP_DIR=/media/Elements
SOURCE_DIR=/var/www

mkdir -p $BACKUP_DIR

TIMESTAMP=`date +%Y-%m-%d-%H%M`
tar cfj $SOURCE_DIR/backup_$TIMESTAMP.tar.gz

find $BACKUP_DIR/* -mtime +7 -exec rm -rf {} \;

 

 

I chmod 777 and execute

 

I get

 

tar: Cowardly refusing to create an empty archive

Try `tar --help' or `tar --usage' for more information.

 

 

 

Any Ideas? 

well the script is working..but I cannot open the zip files

 

gunzip backup_2009-09-15-1516.tar.gz

 

gzip: backup_2009-09-15-1516.tar.gz: not in gzip format

 

 

I modified the tar command slightly to exclude a /test directory I have in /var/www

 

tar cfj $BACKUP_DIR/backup_$TIMESTAMP.tar.gz --exclude=test $SOURCE_DIR

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.