rc.local : copy/backup files between hard drive & ram

Forum rules
Before you post please read this

rc.local : copy/backup files between hard drive & ram

Postby 4nt01n3 on Fri Feb 28, 2014 6:48 pm

Hello,

I'm trying to do something and following it's an example with my /home/antoine/.cache folder :

In my fstab, I want to create /media/ramdisk as a tmpfs
Code: Select all
tmpfs   /media/ramdisk/       tmpfs   "options"   0   0


What I want to do is
1) create /media/ramdisk/.cache folder in it and a symlink to /home/antoine/.cache when I boot
2) copy the .cache folder on the ramdisk to my /home/antoine when I shutdown my computer

Then I've edited the /etc/rc.local file
Code: Select all
#!/bin/sh -e
#
# rc.local
#
/bin/mkdir /media/ramdisk/.cache
/bin/mv /home/antoine/.cache /media/.cache
/bin/ln -s /media/.cache /home/antoine/.cache
exit 0


I've adapted /etc/rc.local & /etc/init.d/rc.local to create etc/rc.local.shutdown & /etc/init.d/rc.local.shutdown files.
- /etc/rc.local.shutdown
Code: Select all
#!/bin/sh -e
#
# rc.local.shutdown
#
rm /home/antoine/.cache
mv /media/ramdisk/.cache /home/antoine
exit 0


- /etc/init.d/rc.local.shutdown (copy & adapt from the rc.local file)
Code: Select all
#! /bin/sh
### BEGIN INIT INFO
# Provides:          rc.local
# Required-Start:    $all
# Required-Stop:
# Default-Start:     0
# Default-Stop:
# Short-Description: Run /etc/rc.local.shutdown if it exist
### END INIT INFO


PATH=/sbin:/usr/sbin:/bin:/usr/bin

. /lib/init/vars.sh
. /lib/lsb/init-functions

do_start() {
   if [ -x /etc/rc.local.shutdown ]; then
           [ "$VERBOSE" != no ] && log_begin_msg "Running local shutdown scripts (/etc/rc.local.shutdown)"
      /etc/rc.local.shutdown
      ES=$?
      [ "$VERBOSE" != no ] && log_end_msg $ES
      return $ES
   fi
}

case "$1" in
    start)
   do_start
        ;;
    restart|reload|force-reload)
        echo "Error: argument '$1' not supported" >&2
        exit 3
        ;;
    stop)
        ;;
    *)
        echo "Usage: $0 start|stop" >&2
        exit 3
        ;;
esac


Can someone check if what I do can work ?
And after that, I need to "update-rc.d", that's right ?
HP Pavilion dv6-1120ef (2009) | Pentium Dual-Core CPU T4200 2*2GHz | 4 Go DDR2 | ATI Mobility Radeon HD 4530 512Mo | LMDE 201403RC 32bits Cinnamon 2.0.14 Kernel 3.13.5
4nt01n3
Level 1
Level 1
 
Posts: 4
Joined: Thu Feb 27, 2014 8:16 am

Linux Mint is funded by ads and donations.
 

Re: rc.local : copy/backup files between hard drive & ram

Postby xenopeek on Sat Mar 01, 2014 2:38 am

Some errors in your /etc/rc.local file, it should be this I think:
Code: Select all
#!/bin/sh -e
#
# rc.local
#
/bin/mv /home/antoine/.cache /media/ramdisk
/bin/ln -s /media/ramdisk/.cache /home/antoine/.cache
exit 0
User avatar
xenopeek
Level 21
Level 21
 
Posts: 14995
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: rc.local : copy/backup files between hard drive & ram

Postby 4nt01n3 on Sat Mar 01, 2014 12:08 pm

Yeah thanks, lots of errors.

(sorry for my english :/ )

I want to copy/backup files between USB stick & RAM because I'm going to travel with just a linux distribution on a USB stick with some files. With my friends we just take an old VAIO i bought in 2000, then if we lost it or if someone steals it, I always have my system and my files to work (writing, editing pictures,...) on another PC.

I'm trying to have the system as minimal as I need and if it's possible copy all is needed on a ramdisk at startup, create symlinks on the usb stick and then backup the ramdisk at shutdown, to improve system & software uses, especially with USB1 connection

So what I've done (here is an exemple with some firefox folders on my own PC)

1) I've created /media/RAMDISK folder

2) In my fstab I mount /media/RAMDISK as tmpfs, as I've done previously

3) I try to adapt the /etc/init.d/rc.local script :

Code: Select all
#! /bin/sh
### BEGIN INIT INFO
# Provides:          rc.local
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 6
# Short-Description: Run /etc/rc.local and /etc/rc.local.shutdown
### END INIT INFO


PATH=/sbin:/usr/sbin:/bin:/usr/bin

. /lib/init/vars.sh
. /lib/lsb/init-functions

do_start() {
   if [ -x /etc/rc.local ]; then
           [ "$VERBOSE" != no ] && log_begin_msg "Running local boot script (/etc/rc.local)"
       /etc/rc.local
       ES=$?
       [ "$VERBOSE" != no ] && log_end_msg $ES
      return $ES
   fi
}

do_stop() {
   if [ -x /etc/rc.local.shutdown ]; then
           [ "$VERBOSE" != no ] && log_begin_msg "Running local shutdown script (/etc/rc.local.shutdown)"
       /etc/rc.local.shutdown
      ES=$?
       [ "$VERBOSE" != no ] && log_end_msg $ES
       return $ES
   fi
}

case "$1" in
    start)
   do_start
        ;;
    restart|reload|force-reload)
        echo "Error: argument '$1' not supported" >&2
        exit 3
        ;;
    stop)
   do_stop
        ;;
    *)
        echo "Usage: $0 start|stop" >&2
        exit 3
        ;;
esac


3) Now I've these /etc/rc.local and /etc/rc.local.shutdown

rc.local

Code: Select all
#!/bin/sh -e
#
/bin/mv /home/antoine/.cache /media/RAMDISK #move files from usb stick to RAMDISK
/bin/ln -s /media/RAMDISK/.cache /home/antoine/.cache #create symlink
/bin/mv /home/antoine/.mozilla /media/RAMDISK
/bin/ln -s /media/RAMDISK/.mozilla /home/antoine/.mozilla
exit 0


rc.local.shutdown

Code: Select all
#!/bin/sh -e
#
/bin/cp -ur media/RAMDISK/.cache /home/antoine/.backup #backup files, it's safety if there is a problem the next time I use the PC
/bin/rm /home/antoine/.cache #remove symlink
/bin/mv /media/RAMDISK/.cache /home/antoine #put the files from RAMDISK to usb stick
/bin/cp -ur /media/RAMDISK/.mozilla /home/antoine/.backup
/bin/rm /home/antoine/.mozilla
/bin/mv /media/RAMDISK/.mozilla /home/antoine
exit 0


Finally I've created symlinks in the /etc/rcX.d folders :
Code: Select all
update-rc.d /etc/init.d/rc.local start 99 2 3 4 5 . stop 01 0 6 .


But something is wrong, that doesn't work, I'm just a new explorer of linux possibilities.
Maybe it's not a good idea (copying/backup files at startup/shutdown may take more time than if I use the system on the usb stick)
Maybe someone know an easiest solution to do what I want ?
HP Pavilion dv6-1120ef (2009) | Pentium Dual-Core CPU T4200 2*2GHz | 4 Go DDR2 | ATI Mobility Radeon HD 4530 512Mo | LMDE 201403RC 32bits Cinnamon 2.0.14 Kernel 3.13.5
4nt01n3
Level 1
Level 1
 
Posts: 4
Joined: Thu Feb 27, 2014 8:16 am


Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 3 guests