You are not logged in.
Since I'm always messing with the config files, being somewhat new to ArchLinux, I was wanting an easy way to make intelligent backup copies of my files ... QUICKLY.
To the rescue, the .bashrc file
Insert this function into your .bashrc file to make quick work of backing up files.
bu () { cp $1 ${1}-`date +%Y%m%d%H%M`.backup ; }
it works pretty simply, say you want to make a backup copy of your /etc/fstab file ...... (now who DOESN'T need a backup copy of that I ask you ? ) You can supply the full path /etc/fstab ......as shown below, or you can cd into the directory the file resides in and just call the file....as shown even FURTHER below
The command is simply bu followed by either the full path and filename, or if your already in the files directory, just bu FILENAME
[root@VistaKillerTwo ~]# bu /etc/fstab
[root@VistaKillerTwo ~]# cd /etc/
[root@VistaKillerTwo etc]# ls -la
---
-rw-r--r-- 1 root root 595 Jan 15 02:54 fstab
-rw-r--r-- 1 root root 595 Jan 15 23:46 fstab-200701152346.backup
---
[root@VistaKillerTwo etc]# bu fstab
[root@VistaKillerTwo etc]# ls -la
---
-rw-r--r-- 1 root root 595 Jan 15 02:54 fstab
-rw-r--r-- 1 root root 595 Jan 15 23:46 fstab-200701152346.backup
-rw-r--r-- 1 root root 595 Jan 15 23:48 fstab-200701152348.backup
---
The backup copy is listed by Year/Month/Day/Hour/Minute ...... and if your REALLY crazy, you could add in seconds....... Makes it easy to keep track of when you made a backup and makes it easy to do too.
Want to remove all the .backup files ???
rm -f *.backup
( I suppose you could alias that as well if you really wanted too lol )..... make sure nothing else is labeling their backups with the same .backup extension or you might erase something you didn't intend too ! Hope it comes in handy for someone else besides myself
Offline
Since I'm always messing with the config files, being somewhat new to ArchLinux, I was wanting an easy way to make intelligent backup copies of my files ... QUICKLY.
To the rescue, the .bashrc file
Insert this function into your .bashrc file to make quick work of backing up files.
bu () { cp $1 ${1}-`date +%Y%m%d%H%M`.backup ; }
it works pretty simply, say you want to make a backup copy of your /etc/fstab file ...... (now who DOESN'T need a backup copy of that I ask you ?
) You can supply the full path /etc/fstab ......as shown below, or you can cd into the directory the file resides in and just call the file....as shown even FURTHER below
The command is simply bu followed by either the full path and filename, or if your already in the files directory, just bu FILENAME
[root@VistaKillerTwo ~]# bu /etc/fstab [root@VistaKillerTwo ~]# cd /etc/ [root@VistaKillerTwo etc]# ls -la --- -rw-r--r-- 1 root root 595 Jan 15 02:54 fstab -rw-r--r-- 1 root root 595 Jan 15 23:46 fstab-200701152346.backup --- [root@VistaKillerTwo etc]# bu fstab [root@VistaKillerTwo etc]# ls -la --- -rw-r--r-- 1 root root 595 Jan 15 02:54 fstab -rw-r--r-- 1 root root 595 Jan 15 23:46 fstab-200701152346.backup -rw-r--r-- 1 root root 595 Jan 15 23:48 fstab-200701152348.backup ---
The backup copy is listed by Year/Month/Day/Hour/Minute ...... and if your REALLY crazy, you could add in seconds.......
Makes it easy to keep track of when you made a backup and makes it easy to do too.
Want to remove all the .backup files ???
rm -f *.backup
( I suppose you could alias that as well if you really wanted too lol )..... make sure nothing else is labeling their backups with the same .backup extension or you might erase something you didn't intend too !
Hope it comes in handy for someone else besides myself
seems like a nice idea, but useless to me, most editors have a built in backup function that creates a backup everytime you save / edit a file.
Offline
interesting ... what about a function to get rid of all the '~' files ...
would rather have backup put key files somewhere safe ie in .backup or /backup
just my thoughts nice function btw 8)
thanks for sharing
Mr Green I like Landuke!
Offline
would rather have backup put key files somewhere safe ie in .backup or /backup
just my thoughts nice function btw 8)
thanks for sharing
You could do that pretty easily too...
bu () { cp $1 /backup/${1}-`date +%Y%m%d%H%M`.backup ; }
This would put all files into /backup/
bu () { cp $1 ~/.backup/${1}-`date +%Y%m%d%H%M`.backup ; }
This would put all the files into ~/.backup (in your home directory)
this would require that you are IN the directory of the file you want to backup. You would move the file with the bu FILENAME ...... you could not use the /path/filename method like i listed above.
Offline
thanks yes full path to /dir ... emmm if your backing up root files then I would say /backup ...
Thanks for your help
Mr Green I like Landuke!
Offline
This version should back up to ~/.backup even if the file isn't in the current directory:
bu () { cp $1 ~/.backup/`basename $1`-`date +%Y%m%d%H%M`.backup ; }
By the way, this isn't just for bash. It should also work in zsh and (maybe?) ksh.
Offline