how to write a script to move files from one directory to another
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
how to write a script to move files from one directory to another
I'm new to Linux and writing scripts, so I hope someone can help me. :-D
We are running rdiff-backup on our server every night under a cron job. It saves the incremental backups in /mnt/backup/rdiff-backup-data but with these increments it has filled up that partition (/dev/sdb2).
I want to have the increments saved on another partition that has much more room in /mnt/backup/var.
I've been searching for info on rdiff-backup to see if I can configure it to automatically save the increments in /mnt/backup/var, but no luck so far.
I'm wondering though if I can write another script that would move the increments from /mnt/backup over to /mnt/backup/var every night automatically?
Can that be done? Can anyone give me an idea how to do this if it's possible?
sure it can be done. I am not familliar with rdiff-backup. you could use find and tar for example. i use a script running out of cron that uses find to create a backcup list based on the -mtime of the files. this file is then used by tar to bakup the files that have changes since my last full archive. this is one way but there are many more. look and dump and diff as well.
"I'm wondering though if I can write another script that would move the increments from /mnt/backup over to /mnt/backup/var every night automatically?"
Rather than writing a second script it would be more straightforward to add your extra commands to the end of the rdiff-backup script that cron runs.
Originally posted by Poetics Take a look at the "cron" function -- it can run a command at specific intervals.
Very easily it could run a "/dev/sdb2# mv * /mnt/backup/var/*" every night at midnight, or 3am, or whenever you decide
We have cron jobs set up for daily, weekly and monthly.
With the daily one it's run every morning at 4am. The rdiff-backup is in that cron job to be ran at 4am, so can I set up a command to be run daily, but at a different time? Because I need to wait for the backup to be finished before I can move my files, so it should be ran at a later time like at 5am.
Can you have a daily cron job, but have it set to run at 2 different times?
Without changing any scripts, and without any user training,
you could create a symbolic link from the full partition to
the partition with more space:
First, manually move anything you want to save from
/mnt/backup/rdiff-backup-data (I assume this is a directory)
to
/mnt/backup/var/rdiff-backup-data (A new directory that you have created)
then,
rm -rf /mnt/backup/rdiff-backup-data (to remove the old directory)
Originally posted by jailbait "I'm wondering though if I can write another script that would move the increments from /mnt/backup over to /mnt/backup/var every night automatically?"
Rather than writing a second script it would be more straightforward to add your extra commands to the end of the rdiff-backup script that cron runs.
------------------------------
Steve Stites
That would be great, but how do I write that script?
I'm so new to this, I'm just not sure what I need to write to make it work.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.