| View previous topic :: View next topic |
| Author |
Message |
scottt n00b

Joined: 04 Jun 2007 Posts: 26
|
Posted: Fri Oct 10, 2008 6:18 am Post subject: [SOLVED] Backup Shell script |
|
|
Hi there,
I need some little inspiration to write a backup script for my most important files:
I basically just copy them with a -u option (for update) to a different HDD.
| Code: | #!/bin/bash
mount -t auto /dev/sdb5/ /fs/backup/
cp -uvR /fs/data/docs/* /fs/backup/docs/
umount /fs/sicherung |
Is there anything better I can do like to check if there are any errors?
As well, now just new or changed data is being changed, how can I automatically delete files from /backup if they are not existing on /data anymore?
Thanks for your recommendations!
Scott
Last edited by scottt on Mon Oct 27, 2008 2:56 pm; edited 2 times in total |
|
| Back to top |
|
 |
a.b. Apprentice


Joined: 23 Mar 2008 Posts: 218 Location: Anus Mundi, Germany
|
Posted: Fri Oct 10, 2008 6:44 am Post subject: Re: Backup Shell script |
|
|
| scottt wrote: |
Is there anything better I can do like to check if there are any errors?
|
YOu could do that using idff or md5.
| Quote: |
As well, now just new or changed data is being changed, how can I automatically delete files from /backup if they are not existing on /data anymore?
|
rsync should be able to do that. |
|
| Back to top |
|
 |
tabanus Guru


Joined: 11 Jun 2004 Posts: 435 Location: UK
|
Posted: Fri Oct 10, 2008 6:48 am Post subject: |
|
|
You could use rsync for this. I have this script
| Code: | #! /bin/bash
rsync -vrptgoD --copy-links --delete Linux_Server::data-backup /mnt/Shared/BACKUP
tar -cpzvf /tmp/backup.tar.bz /mnt/Shared/BACKUP/ |
Where Linux_Server is the name of the rsync server (The PC with the files to be backed up), and /mnt/Shared/BACKUP is the backup directory, and data-backup is the name of the module that I setup to collect all the files to be backed up.
I created a folder in /var that has symlinks to all the various folders that I want backed up, and rsync takes care of deleting files from the backup. I used to do something like you are proposing, and it was taking longer and longer (about 10 minutes), now, it's takes less than a minute. _________________ Never underestimate a hamster. |
|
| Back to top |
|
 |
bunder Bodhisattva


Joined: 10 Apr 2004 Posts: 5150 Location: Hamilton, Ontario
|
Posted: Sat Oct 11, 2008 9:04 pm Post subject: |
|
|
While I'm sure this is also a dupe...
Moved from Off the Wall to Portage & Programming. _________________ bunder @ freenode | bunhax - tame your SMP!
gentoo shells | the remains of UFGO |
|
| Back to top |
|
 |
scottt n00b

Joined: 04 Jun 2007 Posts: 26
|
Posted: Wed Oct 15, 2008 6:54 am Post subject: |
|
|
Ok, I changed the scipt to this:
| Code: | #! /bin/bash
rsync -vrptgoD --copy-links --delete /fs/data/1/ /fs/backup/1/
tar -cpzvf /fs/backup/backup.tar.bz /fs/backup/1/
|
I started it as root and it shows several errors regarding file permissions:
| Code: | [root@localhost /]# /fs/data/backup.sh
building file list ... done
./
rsync: chown "/fs/backup/1/." failed: Operation not permitted (1)
1/
rsync: chown "/fs/backup/1/1" failed: Operation not permitted (1)
1/bookmarks.html
rsync: chown "/fs/backup/1/1/.bookmarks.html.x4NQZE" failed: Operation not permitted (1)
rsync: chown "/fs/backup/1/." failed: Operation not permitted (1)
rsync: chown "/fs/backup/1/1" failed: Operation not permitted (1)
sent 187223 bytes received 54 bytes 374554.00 bytes/sec
total size is 187034 speedup is 1.00
rsync error: some files could not be transferred (code 23) at main.c(977) [sender=2.6.9]
|
As well, I can't open the generated tar.bz file, it shows the following error:
| Code: | bzip2: (stdin) is not a bzip2 file.
/bin/gtar: Child returned status 2 |
What did I wrong? |
|
| Back to top |
|
 |
Hu Veteran

Joined: 06 Mar 2007 Posts: 2595
|
Posted: Wed Oct 15, 2008 9:49 pm Post subject: |
|
|
| scottt wrote: |
| Code: | #! /bin/bash
rsync -vrptgoD --copy-links --delete /fs/data/1/ /fs/backup/1/
tar -cpzvf /fs/backup/backup.tar.bz /fs/backup/1/
|
As well, I can't open the generated tar.bz file, it shows the following error:
| Code: | bzip2: (stdin) is not a bzip2 file.
/bin/gtar: Child returned status 2 |
What did I wrong? |
It is traditional to use the extension .bz2 for bzip2 compressed files, not .bz. More importantly, it is useful to use bzip2 compression, not gzip compression, when creating a file that you intend to decompress with bzip2. Your -z option directs tar to use gzip compression. |
|
| Back to top |
|
 |
Genone Retired Dev


Joined: 14 Mar 2003 Posts: 7742 Location: beyond the rim
|
Posted: Wed Oct 15, 2008 10:05 pm Post subject: |
|
|
| scottt wrote: | | I started it as root and it shows several errors regarding file permissions: |
Let me guess: /fs/backup is a vfat filesystem? Those don't implement basic POSIX ACLs, so rsync can't preserve file ownership/permissions.
Solution: use a real filesystem. |
|
| Back to top |
|
 |
scottt n00b

Joined: 04 Jun 2007 Posts: 26
|
Posted: Sun Oct 19, 2008 1:32 pm Post subject: |
|
|
You're right, it was my last fat partition - changing to ext2 solved it.
Now, I set up a cronjob for this, which works fine. How can I run this every 5 days? I don't wonna do it with the days of the month (1-31) as when I am not turning on my computer on the 5th, a cronjob would'nt follow up on the 6th. How can I do that? |
|
| Back to top |
|
 |
scottt n00b

Joined: 04 Jun 2007 Posts: 26
|
Posted: Sun Oct 19, 2008 4:23 pm Post subject: |
|
|
As I see now, the cronjob
| Code: | * * * 0-7 /fs/daten/sicherung.sh
|
starts my bash script every minute. How can I just make it once (a day)? |
|
| Back to top |
|
 |
fangorn Veteran


Joined: 31 Jul 2004 Posts: 1663
|
Posted: Mon Oct 20, 2008 2:27 am Post subject: |
|
|
The format is
| Code: |
# m h dom mon dow command
30 23 1,6,11,16,21,26 * * /fs/daten/sicherung.sh |
m minute
h hour
dom day of month
mon month
dow day of week
This will start the program every 5 days at half past eleven p.m.
Edit:
replace the list 1,6,11,16,21,26 with a * and it will run every day. * matches every occasion the daemon checks if it has to do something. _________________ Kaum macht man's richtig, schon funktioniert's.
Video Encoding scripts collection |
|
| Back to top |
|
 |
scottt n00b

Joined: 04 Jun 2007 Posts: 26
|
Posted: Mon Oct 20, 2008 11:17 am Post subject: |
|
|
Thanks, this is what the manual told me as well
But the problem is, whats when I am not touring my computer on on the 6th? The cron wont run at the instead 7th then!?
Would the following be a solution or do my computer need to run at least 48 hrs then?
| Code: | | 00 */48 * * * /fs/daten/sicherung.sh |
|
|
| Back to top |
|
 |
TSP__ n00b

Joined: 16 Sep 2008 Posts: 20
|
Posted: Mon Oct 20, 2008 1:28 pm Post subject: |
|
|
rsync is much better for backups and do a check to know what happened...something liek
| Code: |
mount -t auto /dev/sdb5/ /fs/backup/ || echo "Backuo fails!" >> /tmp/backups.log
|
this means do "mount -t auto /dev/sdb5/ /fs/backup/ " o rin case this fail do this "echo "Backuo fails!" >> /tmp/backups.log"
About the crontab entry iyou can do that...[/quote] |
|
| Back to top |
|
 |
scottt n00b

Joined: 04 Jun 2007 Posts: 26
|
Posted: Tue Oct 21, 2008 5:19 pm Post subject: |
|
|
Thanks for the || tip! How can I write something into the log when it's successfull?
How can I write the errors or verbose messages from mount or rsync into my logifle?
The following starts the job every day, but it's ok, I'll leave it then.
| Code: | | 00 */48 * * * /fs/daten/sicherung.sh |
|
|
| Back to top |
|
 |
scottt n00b

Joined: 04 Jun 2007 Posts: 26
|
Posted: Mon Oct 27, 2008 2:56 pm Post subject: |
|
|
OK, the solution is anacon or anacrontab.
anacron is checking, if a process was made after a specific time, if not, it will run that after you have turned on the pc.
man /etc/anacrontab or your favorite search engine helps! |
|
| Back to top |
|
 |
|