My db version is oracle 12c. OS: oracle linux
I have working sh file
export ORACLE_SID=mydborcl
export ORACLE_HOME=/u01/app/oracle/product/12.1.0/db_1
export PATH=$ORACLE_HOME/bin:$PATH
export NLS_LANG='AMERICAN_AMERICA.AL32UTF8'
expdp adminuser/Mypassword#mydborcl schemas=adminuser directory=my_db1 dumpfile=adminuser_`date +%Y%m%d`.dmp logfile=adminuser_`date +%Y%m%d`.log
How can I call that sh file daily or weekly?
How to set it automatically delete the old backup?
you can setup cronjob for rman backup database daily or weekly.
if you want to keep backup for a day or a week, just set retain policy to a week or a day, depend on your need.
please see following steps, that will tell you how to setup rman backup using cron
https://dba.stackexchange.com/questions/139309/cron-and-rman-backups
Related
I would like to setup a daily auto backup of my online myphpadmin database. The backup can be stored on my PC (which is turned on most days) or online somewhere (within myphpadmin somewhere?)
What is the easiest way to achieve this?
myphpadmin has an event scheduler, but requires SQL instructions - but I cant find the commands necessary to make this work.
Thanks for your help
This may depend on your hosting. But i solved it like this:
Create script, eg. backup.sh, with 777 rights, in some not publicly accessible folder
#!/bin/sh
#change directory to your backup directory
cd /home/xxx/backup_dbs/;
#get backup of database of applications
mysqldump --user='myuser' --password='mypw' mydb >tmp_db.sql;
#compress it in zip file
zip app_database-$(date +%Y-%m-%d-%H:%M).sql.zip tmp_db.sql;
#remove sql file
rm -rf tmp_db.sql;
#delete backups older than 20 days
find /home/xxx/backup_dbs/app* -mtime +20 -type f -delete;
and then schedule it via cron jobs
/home/xxx/backup_dbs/backup.sh
It does work on a VPS as well as another cheap reseller account i have. If it doesn't, maybe you just have to call up your hoster to activate execution of shell scripts for you.
We are taking full disk backup of our servers weekly. How do I set up SQL Server 2016 to export all databases automatically to a local folder, every Friday at 6 PM? I'd like to do that to add extra level of protection against database corruption.
I recommend using Ola Hallengren's scripts for database backups. https://ola.hallengren.com/sql-server-backup.html
Remember to DBCC check database before taking a backup and to both validate the backup media and to try your restore scenarios frequently!
Here are the steps from the FAQ:
Download MaintenanceSolution.sql.
In the script, find this line:
SET #BackupDirectory = N'C:\Backup'
and replace C:\Backup with the path to your backup directory.
In the script, find this line:
SET #CleanupTime = NULL
and replace NULL with your cleanup time. The cleanup time is the the number of hours after which the backup files are deleted.
Execute MaintenanceSolution.sql. This script creates all the objects and jobs that you need.
Go into [SQL Server Agent] / [Jobs] and start the jobs that have been created. Verify that these jobs are completing successfully. Verify that the backup files are being created. Check the output files in the error log directory.
Schedule the jobs.
I'm starting to use the PostgreSQL now, and I wonder if I can schedule tasks / work (in SQL) to be done by the db without having to use pgAgent.
I'm working on a system where administrators need to schedule promotions. For example, from day X to day Y there is a Z promotion. This must be done in the system interface (UI), on a page that will send the command to the database. All I need is to perform a SQL command when a proper time comes.
I have searched on the internet, and all I find is about pgAgent or how to configure it. I do not want it. From what I saw, the pgAgent only works by pgAdmin interface, and system administrators can not lay a finger on pgAdmin... Or not (I'm new to PostgreSQL)...? :/
In pgAdmin, when creating a new job I also clicked on the help button but there does not talk much except set everything through pgAdmin interface.
Is there any way to achieve this? Are there alternatives?
Thank you for your attention.
PgAgent doesn't work just through PgAdmin, but rather, PgAdmin is the only (current) GUI that interfaces with the PgAgent tables. PgAgent is a service that interacts exclusively with its own set of tables, which can be modified and reported on by any software, not just PgAdmin. PgAdmin can be very useful since it implements multi-stepped jobs, and the results are stored in the database and can be queried or custom reports can be made.
There are many alternatives, from developing your own PgAgent-like tool, to using cron in Linux/Unix/Cygwin or Scheduled Tasks in Windows.
For example, in Linux, a daily table export can be implemented in cron by adding a batch file in /etc/cron.daily/ like
sudo -i -u postgres psql -c "copy foo.bar to '/var/lib/dbexports/foo-bar.csv' with csv header" foo_db
or in a file in /etc/cron.d/ to export that file specifically on Mondays at 5:30 like
30 5 * * 1 postgres psql -c "copy foo.bar to '/var/lib/dbexports/foo-bar.csv' with csv header" foo_db
or similar on any user's crontab.
I only have access to the command line processor and I would like to set up a backup policy to do an offline backup once a day of a db2 database.
Can anyone point me in the right direction?
To do a single offline backup I know the code is
BACKUP DATABASE <database> TO <“drive/location”> <params>
However I can not figure out how to schedule this
If you are using LUW, you can:
In Windows, create a task in the Taks Schedule with the backup command. - http://windows.microsoft.com/en-gb/windows/schedule-task#1TC=windows-7
In linux, put the command in the crontab of a user with the privileges to execute the backup. Remember to load the db2 instance profile.
You can configure automatic backups in any OS - http://pic.dhe.ibm.com/infocenter/db2luw/v10r5/topic/com.ibm.db2.luw.sql.rtn.doc/doc/r0052291.html
If you are using Windows OS, then you create a new task and on the action tab:
Action: Start a program
Program/script: "D:\Program Files\IBM\SQLLIB\BIN\db2cmd.exe" (path there the db2cmd.exe is located)
Add arguments (optional): /c /w /i db2 backup database DBNAME to X:\Backup COMPRESS WITHOUT PROMPTING
Start in (optional): blank
The command above will backup database DBNAME to X:\Backup folder compressing the DB.
DB2 v10.1 database on WINDOWS 7.
Can somebody share about creating a database backup of the DB2? I could not find detailed instructions.
Thanks in advance for any help in this matter
Have you tried looking at the documentation? Perhaps the "Data Recovery Reference"?
http://pic.dhe.ibm.com/infocenter/db2luw/v10r1/topic/com.ibm.db2.luw.admin.ha.doc/doc/c0006150.html
In a db2cmd window type \DB2 HELP BACKUP\ for more complete command syntax. The simplest form of the command is
DB2 BACKUP DATABASE <database name>
Optim Studio in 9.7 and 10.1 and Control Center in 9.7 have GUI's to assist with these tasks as well.
For a local backup you can use a simple command line command also provided in the other answers:
db2 backup database <name>
If you want a more automated solution that's more for "enterprise" then you should look into IBM Tivoli Storage Manager for example. DB2 supports making backups to network storaged TSM on the fly with incremental backups without disrupting the local database from working. I.e. you can run queries while the backup is running.
For TSM you need log archiving enabled on the database, you can do that with command should be:
db2 update db cfg using LOGARCHMETH1 TSM
After you have enabled log archiving you can create a backup script and schedule it:
set DB2INSTANCE=DB2
"C:\IBM\ProductName\db2\BIN\db2cmd.exe" /c DB2.EXE backup db WPSDB user <DOMAINUSERNAME> using <DOMAINUSERPASSWORD> online use tsm include logs
Here's a link to a full tutorial: http://www.codeyouneed.com/db2-backup-using-tsm/
For detailed step by step guide to configure DB2 backup, you can refer:
DB2 v9.7 on AIX(x64) backup configuration for TSM v7.1
Every step form planning, preparation and execution is explained with diagrams.
Basic steps are:
Download Appropriate TSM API 32/64 bit based on db2level from passport advantage
Extract TSMCLI_AIX.tar
Login as root and enter "SMITTY INSTALL"
Select required components:
tivoli.tsm.client.ba.64bit,
tivoli.tsm.client.api.64bit etc.
If not using TSM client GUI then no need to install
Tivoli.tsm.client.jbb.64bit
Tivoli.tsm.filepath
Now apply steps mention in the link as example to configure for File level and DB2 level backup as per your environment.